PDF Editing Issues

How to Save and Restore PDF Form Fields with Acrobat Layers

Tauseeq MagsiTauseeq Magsi Oct 28, 2026 868 views

Question details

The user needs to ensure that PDF form fields associated with hidden layers maintain their correct visibility state when the document is saved and reopened.

How to Save and Restore PDF Form Fields with Acrobat Layers
Product
PDF Editor / Adobe Acrobat
Device & OS
not provided
Scenario
Using JavaScript to manage layer configurations and form field visibility in a PDF document.
Observed behavior
The LayerConfig field fails to save the last-used state, causing form fields associated with hidden layers to incorrectly appear after reopening the PDF.
Before you start

Ensure your PDF editor supports document-level JavaScript and Optional Content Groups (OCGs) for layer management. It is highly recommended to keep a backup of your original PDF before adding or modifying any document scripts.

Solution 1Recommended

Configure Document-Level JavaScript to Save and Restore Layer States

Use document-level scripts to capture the active Optional Content Group (OCG) states upon closing and restore them upon opening.

When layers (OCGs) are toggled, the associated form fields might not retain their visibility state natively after the file is closed. Implementing a hidden text field (often named 'LayerConfig') combined with opening and closing scripts ensures the exact state is preserved across sessions.

1
Create a LayerConfig Field

Add a text field named 'LayerConfig' to your PDF. Set this field to be hidden so users cannot see it, but ensure it is NOT excluded from saving or printing, as it needs to store the state data permanently.

2
Add a Will-Close Script

Navigate to the document's JavaScript properties and add a 'Document Will Close' script. Program this script to iterate through the OCGs, record the names of the active layers, and write this data as a string value into the 'LayerConfig' field.

3
Add an Open-Document Script

Add a 'Document Did Open' script that reads the stored string from the 'LayerConfig' field. The script should then iterate through the document's layers and set their visibility to match the saved state.

4
Save and Test the Document

Save your PDF document. Toggle several layers on and off, close the document, and reopen it to verify that the form fields and layers display in their correct, last-used configurations.

Configure Document-Level JavaScript to Save and Restore Layer States
Verify Field Properties: If the LayerConfig field is set to 'hidden but doesn't print' or has property flags that prevent it from retaining data, the script will fail to save the state. Always double-check its properties.
Seamless PDF Management

Edit and Manage PDF Forms with WPS Office

WPS Office provides a comprehensive PDF editor that allows you to easily view, fill, and manage interactive PDF forms without writing complex scripts for basic document handling.

  1. 1. Open PDF in WPS: Launch WPS Office and open your PDF document containing the interactive form fields.
  2. 2. Access Form Tools: Navigate to the 'Form' or 'Edit' tab to view all available form fields and interactive elements.
  3. 3. Edit and Save: Fill out or modify the form fields as needed, then click 'Save' to preserve your inputs and layer visibility seamlessly.
Easily view and fill interactive PDF form fields.High compatibility with standard PDF elements and Microsoft Office formats.Lightweight application for fast PDF loading, editing, and saving.Seamlessly convert between PDF, Word, Excel, and PowerPoint.
microsoft office alternative - wps office

Frequently Asked Questions

Why do hidden PDF form fields become visible when I reopen the document?

This typically happens because the PDF viewer resets the layer (OCG) visibility to its default state upon opening, ignoring the state it was in when closed unless specifically saved and restored via JavaScript.

What is an OCG in a PDF document?

OCG stands for Optional Content Group, which is the technical term for layers in a PDF. They allow content, such as specific form fields or graphics, to be selectively viewed or hidden.

Can I hide the LayerConfig field so users don't see it?

Yes, you can set the LayerConfig text field to be hidden in its properties. However, you must ensure it is not set to a state (like read-only or do-not-save) that prevents it from retaining data when the document is saved.