Copy link to clipboard
Copied
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:
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);
}
}
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
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
OK.
You find the solution: you cannot use this script alone:
this.getOCGs().locked = true;
It is first necessary to define "i".
Copy link to clipboard
Copied
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().
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more