Show Selected PDF Pages in Two-Page View with Acrobat JavaScript
Question details
Configure a PDF to switch to a two-page view for a selected middle section while using a different layout elsewhere.
- Product
- Adobe Acrobat
- Device & OS
- not provided
- Scenario
- A long PDF contains a section that should be displayed in two-page view when readers reach it.
- Observed behavior
- The desired layout changes when a selected page opens, with a different layout used outside the section.
Open the PDF in an Acrobat version that supports editing page actions and has JavaScript enabled. Identify the physical page where the section begins; Acrobat JavaScript uses zero-based page indexes, which may differ from printed page labels.
Add an Acrobat page-open action to switch layouts
Use a page-open action to request a two-page layout when a reader reaches the start of the section.
The action changes the viewer layout when the specified page opens; it does not permanently assign a separate layout to that page. Viewer support and security settings can affect whether the script runs.
Open the PDF in Acrobat and choose Tools > JavaScript > JavaScript Debugger. The available menu names can vary by Acrobat version.
In the console, enter: this.setPageAction(350, "Open", "this.viewState = {pageViewLayoutMode:3};");. This targets the 351st physical page because page indexes start at zero. Replace 350 with the index for your section's first page.
Select the statement in the console and run it using the debugger's execution command, then choose File > Save to save the page action in the PDF.
Navigate away from the target page and open it again. Check the layout in the Acrobat versions and viewing environments your readers use.
If the layout must change back, add another page-open action on a page outside the section using a layout value verified for your Acrobat environment. Test forward and backward navigation and direct jumps to pages.

Read PDFs and work with Office files in WPS Office
WPS Office is a free, lightweight, easy-to-use Office alternative with a familiar interface and support for common Microsoft Office formats, making it easy to move existing files into your workflow. It can open PDFs, but it does not fix Acrobat-specific JavaScript page actions.

Frequently Asked Questions
Why does the script use 350 for page 351?
Acrobat JavaScript page indexes start at zero, so index 350 refers to the 351st physical page. Check the physical page position rather than relying only on a printed page label.
Will the layout automatically switch back after the section?
No. The example only requests a layout change when the target page opens. Add and test a separate page-open action outside the section if you need to request a different layout.
What happens if a reader jumps into the middle of the section?
The action on the section's first page may not run if that page is skipped. Test direct navigation and consider where additional page actions are needed.
Will this JavaScript work in every PDF viewer?
No. Support for Acrobat JavaScript and page actions varies, and security settings can block scripts. Test the saved PDF in the Acrobat versions and other viewers your audience uses.




