PDF Editing Issues

Preserve PDF Layer Visibility After Reopening in Adobe Acrobat

Huma Ashraf ChHuma Ashraf Ch Nov 18, 2026 869 views

Question details

Keep the selected PDF layer visibility settings after saving, closing, and reopening the document.

Preserve PDF Layer Visibility After Reopening in Adobe Acrobat
Product
Adobe Acrobat and Acrobat Reader
Device & OS
not provided
Scenario
A PDF uses drop-down menus and checkboxes to control layer visibility.
Observed behavior
Layers revert to their default visibility settings when the saved PDF is reopened.
Before you start

Open the PDF in Adobe Acrobat and confirm that it contains layers and editable form controls. Check that document security allows form changes and that JavaScript is enabled in the PDF viewer used for testing.

Solution 1Recommended

Store layer states in hidden fields and restore them on open

Use this approach when users need their layer selections to persist across sessions, including when the file will be opened in Acrobat Reader.

A document-level script can read and set PDF layer visibility, but the selected states must also be stored in the PDF to survive closing. Hidden form fields provide that storage.

The example associates fields with layers by their order in Acrobat's getOCGs() array. If layers are added, removed, or reordered, update and retest the field mapping.

1
Create hidden state fields

In Acrobat, open Prepare a form and add one text field for each layer. Name the fields LayerState_0, LayerState_1, and so on, matching the layer order returned by getOCGs(). In each field's Properties, set its visibility to Hidden.

2
Add the document script

Open All tools > Use JavaScript > Document JavaScripts, add a script, and enter: function saveLayerStates() { var a = this.getOCGs(); if (!a) return; for (var i = 0; i < a.length; i++) { var f = this.getField('LayerState_' + i); if (f) f.value = a[i].state ? '1' : '0'; } } function restoreLayerStates() { var a = this.getOCGs(); if (!a) return; for (var i = 0; i < a.length; i++) { var f = this.getField('LayerState_' + i); if (f && f.value == '1') a[i].state = true; else if (f && f.value == '0') a[i].state = false; } } restoreLayerStates();

3
Save states after control changes

In Prepare a form, open the Properties > Actions tab for each checkbox or drop-down that changes layers. Add a Run a JavaScript action containing saveLayerStates(); after the existing action that changes visibility, so the fields capture the updated states.

4
Test saving and reopening

Use the controls to change layer visibility, select File > Save, close the PDF, and reopen it. Repeat the test in Acrobat Reader if Reader users need to use the file.

Store layer states in hidden fields and restore them on open
Reader and security limitations: The file must permit form changes to be saved, and the viewer must support and allow the required JavaScript and layer operations. Test in the intended Reader version; other PDF viewers may not restore the states.
Free Microsoft Office alternative

Work with PDFs and Office files in WPS Office

WPS Office is a free, lightweight alternative with a familiar interface for working across documents, spreadsheets, presentations, and PDFs. Its Office format support makes it easier to move existing files into your workflow. Use Acrobat to implement and test the JavaScript-based layer persistence described above.

Open and work with PDF documents alongside Office filesCompatible with Microsoft Word, Excel, and PowerPoint formatsFamiliar interface for a smoother transition from Microsoft OfficeFree, lightweight suite for everyday productivity
microsoft office alternative - wps office

Frequently Asked Questions

Why do my PDF layers return to their default settings?

Changing visibility during a viewing session does not necessarily save those choices as the next session's state. Store the selections in form fields and restore them with a document-open script.

Can Acrobat Reader retain the selected layer states?

It may work if the states are stored in form fields, the form changes can be saved, and Reader allows the required JavaScript. Test the complete save-and-reopen workflow in the intended Reader version.

Where do I add the script that restores layers?

In Adobe Acrobat, open All tools > Use JavaScript > Document JavaScripts. Add the restore function and call it from the document-level script so it runs when the PDF opens.

What happens if I add or reorder PDF layers?

The example uses the order returned by getOCGs() to match layers to hidden fields. Check the mapping and update the fields or script after changing the layer structure.