Configure Acrobat PDF Buttons to Control Layer Visibility
Question details
The author needs PDF buttons that reliably control layer visibility across Acrobat versions.

- Product
- Adobe Acrobat
- Device & OS
- not provided
- Scenario
- A PDF author is configuring interactive buttons for recipients who use different Acrobat versions.
- Observed behavior
- The desired result is for each button to show or hide the intended PDF layer consistently in the Acrobat versions used by recipients.
Open the PDF in an Acrobat edition that can edit form fields, and check the Layers panel for the exact names of the layers you want to control. Identify the Acrobat or Reader versions recipients use and whether JavaScript is enabled.
Set button actions to control named PDF layers
Use a Mouse Up JavaScript action to set the visibility of a specific layer when the button is clicked.
PDF layers are optional content groups. Acrobat JavaScript can find them by name and set their visibility; setting an explicit visible or hidden state is more predictable than toggling an unknown starting state.
The Show/Hide a Field action controls form fields, not PDF layers. Use it only if the items you need to show or hide are form fields.
Open the Layers panel in Acrobat and note the exact name of the target layer. If multiple layers share a name, identify or rename them before using a name-based script.
Open All tools > Prepare a form, then double-click the button to open its Properties dialog. Menu names may vary by Acrobat version.
On the Actions tab, select Mouse Up as the trigger and Run a JavaScript as the action, then click Add.
In the JavaScript editor, enter: var groups = this.getOCGs(); if (groups) { for (var i = 0; i < groups.length; i++) { if (groups[i].name === "Layer 1") groups[i].state = true; } } Replace Layer 1 with the exact layer name. Use false instead of true for a button that hides the layer, then save the action.
Save the PDF, reopen it, and click each button in the Acrobat and Reader versions recipients use. Check the Layers panel and page content to confirm the intended visibility changes.

Use Show/Hide a Field for form fields
Choose this built-in action when the objects to control are form fields rather than PDF layers.
Work with PDF and Office files in WPS Office
WPS Office is a free, lightweight alternative with a familiar interface for working with PDF and Microsoft Office files. Its format compatibility makes it easy to move everyday documents into WPS, but configuring Acrobat-specific layer-control JavaScript remains an Acrobat task.

Frequently Asked Questions
Can Show/Hide a Field control a PDF layer?
No. In the button Properties dialog, Show/Hide a Field targets form fields. To control a PDF layer, use a supported JavaScript action that changes the optional content group's state.
Why does my layer button work in one viewer but not another?
The viewer may not support Acrobat JavaScript or PDF layers, or JavaScript may be disabled by security settings. Test the saved file in the specific Acrobat or Reader versions recipients use.
Should a button toggle a layer or set it to a fixed state?
A fixed state is more predictable when the starting visibility is uncertain. In the JavaScript action, set the layer's state to true to show it or false to hide it.
What should I check if the button changes the wrong layer?
Open Acrobat's Layers panel and compare the layer name with the name in the button's JavaScript. Check for duplicate names, because a name-based script can affect every matching layer.




