PDF Editing Issues

How to Turn On All PDF Layers Using Acrobat JavaScript

Algirdas JasaitisAlgirdas Jasaitis Nov 5, 2026 870 views

Question details

The user needs to programmatically activate all optional content groups (layers) within a PDF document using Acrobat JavaScript, ignoring the default states assigned in Illustrator or Acrobat.

How to Turn On All PDF Layers Using Acrobat JavaScript
Product
Adobe Acrobat
Device & OS
not provided
Scenario
Managing complex PDFs with multiple layers where making every layer visible simultaneously is required without manually toggling each one.
Observed behavior
Layers are turned off by default based on initial saved states, and need to be forced to a visible state in the current view using a script.
Before you start

Ensure you have access to Adobe Acrobat Pro to use the JavaScript Debugger console, and remember that scripts modifying the current view state may not permanently alter the saved file.

Solution 1Recommended

Use the Acrobat JavaScript Console to Toggle All Layers

Execute a brief JavaScript loop to fetch all Optional Content Groups (OCGs) and instantly change their current state to visible.

Instead of trying to detect specific layer names or evaluating which layers are currently hidden, you can force all layers to turn on universally.

Changing the state of a layer through this specific script does not mark the document as modified. Consequently, the layers will revert to their initial default state when the document is reloaded.

1
Open the JavaScript Debugger

Launch Adobe Acrobat Pro, open your PDF document, and navigate to 'Tools' > 'JavaScript'. Click on 'Document JavaScripts' or press Ctrl+J (Windows) / Cmd+J (Mac) to open the JavaScript Debugger console.

2
Input the layer visibility script

In the console window, type or paste the following code: var ocgsArr = this.getOCGs(); for (var i in ocgsArr) { ocgsArr[i].state = true; }

3
Execute the script

Highlight all the text you just pasted into the console, then press the Enter key on your numeric keypad (or Ctrl+Enter) to run the script. All layers in your document will instantly become visible.

Use the Acrobat JavaScript Console to Toggle All Layers
Temporary Visibility Change: Because this script alters the 'current state' (state = true) rather than the 'initial state', the layers will return to their original hidden or visible settings the next time you open the PDF.

Easily Manage PDF Layers Visually with WPS Office

If you want to avoid writing JavaScript code to manage your document's visibility, WPS Office provides an intuitive visual interface to effortlessly toggle and manage PDF layers.

  1. 1. Open your PDF in WPS Office: Launch WPS Office and open your multi-layered PDF document by clicking 'Open' on the home screen.
  2. 2. Access the Layers Panel: Navigate to the left-hand navigation pane and click on the 'Layers' icon (it looks like stacked sheets of paper) to reveal all Optional Content Groups.
  3. 3. Toggle layer visibility: Click the 'Eye' icon next to any layer's name to instantly show or hide that specific layer within your document.
No coding or JavaScript knowledge requiredIntuitive sidebar to view and manage all PDF layers at a glanceFully compatible with multi-layered PDFs created in Adobe Illustrator and AcrobatLightweight program size with fast document rendering
QA img-9

Frequently Asked Questions

Why do my PDF layers hide again after reopening the file?

When you use the JavaScript command `ocgsArr[i].state = true`, you are only modifying the current session's view state. To make it permanent, you would need to modify the layer's initial state (`initState`) and save the document.

What is an Optional Content Group (OCG)?

An Optional Content Group (OCG) is Adobe Acrobat's technical term for a PDF layer. It allows document authors to control the visibility of specific content elements—such as multiple languages or alternative graphics—within a single PDF file.

Can I embed this JavaScript so users can click a button to show layers?

Yes. You can attach this JavaScript snippet to a custom PDF Button or a Bookmark. When the user clicks the button or bookmark, the script will execute and reveal all layers immediately.

Does this script work in free PDF readers?

Running custom JavaScript through the console typically requires advanced PDF software like Adobe Acrobat Pro. However, buttons containing this script can often be clicked and executed in standard free readers, provided they support basic JavaScript interactions.