Skip to main content
Inspiring
February 21, 2017
Answered

Save layer state on close

  • February 21, 2017
  • 1 reply
  • 7212 views

Hi

I have a relatively complicated form that is using buttons to show/hide multiple layers.

Everything is working well, but I am trying to find a way for the layer visibility state to be saved when the file is saved, so that when the PDF is next opened the layers are still in the same state.

Is this possible?

This topic has been closed for replies.
Correct answer Karl Heinz Kremer

You will have to save the layer state in e.g. a hidden form field and then restore it again from that hidden field the next time the document is opened. There is nothing built into Acrobat that would do this for you.

1 reply

Karl Heinz  Kremer
Community Expert
Karl Heinz KremerCommunity ExpertCorrect answer
Community Expert
February 21, 2017

You will have to save the layer state in e.g. a hidden form field and then restore it again from that hidden field the next time the document is opened. There is nothing built into Acrobat that would do this for you.

Joel Geraci
Community Expert
Community Expert
February 22, 2017

Elaborating on Karl's answer...

The initiState property of the OCG object is Read/Write in Acrobat but Read-only in Reader. If you need Reader to store the state of the layer, then storing it in a hidden field is the only viable approach.

If you anticipate that all of your users will have Acrobat or you only need Acrobat users to save, then the initState can be used to change the default state of the layer.

try67
Community Expert
Community Expert
March 19, 2019

Hi,

When I save the document using this script it turns on all layers when I reopen?

Do I need to put layer names in the hidden drop down?

Thanks


The state of the layers is not saved when you save the file. They will revert to their Init State when you open it.

The solution is either to change the initState property (note, that's not possible in Reader), or to save the states to something like a text field and then use a doc-level script to read the contents of that field and show/hide the layers based on it each time the file is opened.