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.
The global object can also be used to store the layer states.
Thank you Try67. I attempted to set the init state using the following script for the same checkbox that controls visibility.
this.setOCGstate().initstate = false;
else this.setOCGstate().initstate = true;
This isn't working exactly as I want. It isn't consistently retaining the layer visibility each time the document is reopened. It also isn't resetting it once that field is unchecked. What am I doing wrong?
I am interested in you idea about saving the visibility in another field. Any example of how to do that? I wouldn't have ever thought of that, so thanks so much.
JS is case-sensitive. The name of this property is initState, not initstate...
1 person found this helpful
Also, there's no such method as setOCGstate...
The correct syntax is:
this.getOCGs().initState = false;
That worked! Thanks so much for the help try67.