Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
1

Adobe Acrobat crashes when changing OCG (Layer) properties via javascript

Community Beginner ,
Oct 19, 2016 Oct 19, 2016

I work with quite a few layers (aka OCGs / optional content groups) in order to have multiple locales within the same document. I wrote a few scripts that help to lock layers (so they cannot be made visible from within the UI), and to show or hide layers (based on a pattern matching of their name). These functions basically loop through all layers and conditionally chage the locked, state or initState properties is this kind of way:

  • this.getOCGs().locked = true;
  • this.getOCGs().state = isVisible;
  • this.getOCGs().initState = isVisible;

Now, at about 40 to 50 layer property manipulations (no matter if the same layer or different layers), Acrobat simply crashes. These crashes were consistantly reproducable on any version since Acrobat X (Reader and Pro), both on Mac and Windows (whereas the Windows Version seems to allow a few more manipulations).

Is there any known workarround? If not, how can we paying customers make Adobe fix this as quickly as possible?

Thanks

Dirk

Update: acutally, not just property manimullation causes the issue. Simple read-access already leads to the crashes. Create a PDF with some 50-60 layers and run the following code:

for (i=0; i<this.getOCGs().length; i++) {

  var showLayer = false;

  for (var x = 0; x < 6; x++) // increase the loop count if you have less than 50 layers / OCGs

  {

    var layerState = this.getOCGs().state;

    console.println("Layer #"+i+", state=["+layerState+"], loop #" +x);

  }

}

TOPICS
Acrobat SDK and JavaScript , Windows
1.5K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Beginner , Dec 04, 2016 Dec 04, 2016

Since I got no reply in the forum, I played around with various different approaches in oder to get at least something working. I actually discovered that (confirmed at least on Acrobat DC Mac) Acrobat seems not to like the repetitive direct access to the OCG Objects. When assigning them to a variable, I can run the example below without any crashes:

var ocgs = this.getOCGs();

var ocgCount = ocgs.length;

for (i=0; i<ocgCount; i++) {

  var showLayer = false;

  for (var x = 0; x < 100; x++) {

    var la

...
Translate
Community Beginner ,
Dec 04, 2016 Dec 04, 2016

Since I got no reply in the forum, I played around with various different approaches in oder to get at least something working. I actually discovered that (confirmed at least on Acrobat DC Mac) Acrobat seems not to like the repetitive direct access to the OCG Objects. When assigning them to a variable, I can run the example below without any crashes:

var ocgs = this.getOCGs();

var ocgCount = ocgs.length;

for (i=0; i<ocgCount; i++) {

  var showLayer = false;

  for (var x = 0; x < 100; x++) {

    var layerState = ocgs.state;

    console.println("Layer #"+i+", state=["+layerState+"], loop #" +x);

  }

}

Though not intuitive, it seems to do the trick for me, so I poste my approach for any one else running into a similar issues.

Let me know if it works for you as well.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 07, 2016 Dec 07, 2016

Hi.

You can lock all layers once for all, JavaScript can show/hide layers even if they are locked.

Locking a layer just prevent the user to change its visibility using UI.


Acrobate du PDF, InDesigner et Photoshopographe
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Dec 07, 2016 Dec 07, 2016

HI JR, thanks, I know, this is not an issue (I only need to be able to switch the language in the form, so there is no "secret" in any of the other layers). This is not the problem I am describing here, though. The problem is, that when accessing layer properties directly via this.getOCGs() repeatedly, then Acrobat simply crashes.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 08, 2016 Dec 08, 2016

OK.

You find the solution: you cannot use this script alone:

this.getOCGs().locked = true;

It is first necessary to define "i".


Acrobate du PDF, InDesigner et Photoshopographe
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Dec 08, 2016 Dec 08, 2016
LATEST

Never mind, JR. This was just a code snipped from my method. Obviously the "i" is set. Otherwise the JavaScript engine would just throw an exception (visible in the debug console) and not crash Adobe Acrobat entirely. Don't bother spending your time on this, the only ones who can fix the source of the problems are Adobe devs, as only they have access to the code. I suppose there are certain memory segments not released after accessing this.getOCGs().

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines