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

How can I retain Layer visibility once a document is closed

New Here ,
Oct 12, 2016 Oct 12, 2016

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?

TOPICS
Acrobat SDK and JavaScript
1.1K
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 Expert , Oct 12, 2016 Oct 12, 2016

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

The correct syntax is:

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

Translate
Community Expert ,
Oct 12, 2016 Oct 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.

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
Engaged ,
Oct 12, 2016 Oct 12, 2016

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

J-

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
New Here ,
Oct 12, 2016 Oct 12, 2016

Thank you Try67. I attempted to set the init state using the following script for the same checkbox that controls visibility.

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

    this.setOCGstate()[1].initstate = false;

else this.setOCGstate()[1].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.

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 ,
Oct 12, 2016 Oct 12, 2016

JS is case-sensitive. The name of this property is initState, not initstate...

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 ,
Oct 12, 2016 Oct 12, 2016

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

The correct syntax is:

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

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
New Here ,
Oct 12, 2016 Oct 12, 2016
LATEST

That worked! Thanks so much for the help try67.

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