How to Keep Acrobat PDF Form Layers Visible After Saving
Question details
The user needs a way to maintain the visibility state of dynamically triggered PDF layers after a filled form is saved and reopened.

- Product
- PDF Editor
- Device & OS
- not provided
- Scenario
- Filling out and saving dynamic interactive PDF forms that rely on optional content groups to show different fields based on the vendor's answers.
- Observed behavior
- When the completed form is saved and reopened, the text in the entered fields is retained, but the selected layers are turned off and become invisible.
Ensure your PDF editing software supports document-level JavaScript execution and verify that your PDF viewer's security settings permit scripts to run when opening the file.
Use JavaScript to Store and Restore Active Layer States
Create a hidden field to save the names of the active layers before saving, and use an initialization script to restore them upon opening.
By default, the visibility states of Optional Content Groups (OCGs) or layers are not automatically saved with standard form field data. To persist these states, you must programmatically capture which layers are active right before the document saves, and reapply those states when the document is opened again.
Add a new text field to your PDF form, name it something recognizable like 'LayerConfig', and set its properties to 'Hidden' and 'Read-Only'.
Insert a document-level JavaScript configured to trigger just before the document saves. This script must read the currently active optional content groups and write their names as a string into the 'LayerConfig' hidden field.
Write a second document-level JavaScript that runs when the document opens. Use the 'initState' property or a custom loop to read the 'LayerConfig' field values and turn the corresponding layers back on.
Save the PDF, close it, and reopen it in your default PDF viewer to verify that the layer visibility matches the state it was in prior to saving.

Manage and Fill Interactive PDF Forms with WPS Office
WPS Office provides a highly compatible and lightweight PDF editor designed to seamlessly handle interactive form fields, checkboxes, and document layouts without complex configurations.
- 1. Open your PDF form: Launch WPS Office and open your interactive PDF file using the built-in PDF reader.
- 2. Fill the form fields: Click directly on the interactive fields, drop-down menus, or checkboxes to input your information.
- 3. Save your data securely: Click the 'Save' icon or press 'Ctrl+S' to ensure all your inputted data and formatting remain intact for the next time you open it.

Frequently Asked Questions
Why do PDF layers disappear after I save and reopen a file?
PDF layers, technically known as Optional Content Groups (OCGs), are primarily designed for dynamic display. Most PDF viewers revert layers to their default initial state upon reopening unless a specific script is used to capture and restore the active state.
What is the 'initState' property in PDF JavaScript?
The 'initState' property is part of the JavaScript API for PDFs. It allows developers to define the initial on or off visibility state of document layers when the file is first opened.
Will my PDF JavaScript work in any PDF viewer?
Not necessarily. Support for document-level JavaScript varies widely among different PDF viewers and web browsers. It is highly recommended to test your scripts in the specific environments your users will rely on.




