Skip to main content
Mantis_nyc
Participant
October 12, 2016
Answered

How can I retain Layer visibility once a document is closed

  • October 12, 2016
  • 1 reply
  • 1252 views

I have a PDF document with multiple layers. Depending on the stage of the project certain layers need to be turned on or off. For example, once I move from the development stage to the production stage, development will be unchecked and production will be checked for as long as the document remains in that stage. Layer visibility is controlled with this script:

if (event.target.value=="Off")

    this.getOCGs()[1].state = false;

else this.getOCGs()[1].state = true;

It works great, but when the document is closed and reopened all layers are reset to their default state: Off. I've tried a ton of variables (including View State, InitState, etc) but can't get the initial visibility to remain on when the file is opened. Any thoughts on how to accomplish this?

This topic has been closed for replies.
Correct answer try67

Also, there's no such method as setOCGstate...

The correct syntax is:

this.getOCGs()[1].initState = false;

1 reply

try67
Community Expert
Community Expert
October 12, 2016

You need to set the OCG's initState property, but that can only be done in Acrobat.

Alternatively, you can use a script that saves the current layers visibility to a hidden text field, for example, and then sets their visibility from the data in that field when the file is opened.

JoelGeraci_Datalogics
Participating Frequently
October 12, 2016

The global object can also be used to store the layer states.

J-