How to Navigate Directly to a Spawned Template Page in PDF via JavaScript
Question details
The user wants to automatically redirect the document view to a newly spawned page template within a PDF using offline JavaScript.

- Product
- Adobe Acrobat / PDF Editors
- Device & OS
- not provided
- Scenario
- Creating dynamic PDF forms where a new page is generated from a template, requiring the user to be taken to that new page immediately after generation.
- Observed behavior
- A specific JavaScript command is needed to shift the active view to the newly generated page index.
Ensure you have access to the JavaScript console or the action properties in your PDF editor, and verify the exact index where your page template will be spawned.
Use JavaScript to Set the Target Page Number
Apply a simple JavaScript command to change the current page view to the newly spawned page using zero-based index targeting.
In PDF JavaScript, the document's page numbers are zero-based. This means the first page is index 0, the second page is index 1, and so on. When you spawn a template, you must calculate or know the new page's index to navigate to it correctly.
Run your existing JavaScript command to spawn the page template and determine its resulting page index (represented as X).
Immediately after the spawn command in your script, add the following line of code: this.pageNum = X;
Ensure the value of X reflects the zero-based indexing system. For example, if the newly spawned page is the 5th page in the document, the value of X must be 4.
Trigger the offline JavaScript action in your PDF document to confirm that the view automatically jumps to the newly created page.

Edit and Manage PDFs Easily with WPS Office
While advanced JavaScript for dynamic PDFs is heavily tied to specific enterprise tools, WPS Office provides a lightweight, highly compatible alternative for everyday PDF editing, form filling, and document management. It seamlessly handles Word, Excel, PowerPoint, and PDF files in one familiar interface.
- 1. Download WPS Office: Visit the official WPS website and download the free installer for your operating system.
- 2. Install and Launch: Run the installation file and open the WPS Office desktop application.
- 3. Open your PDF: Drag and drop your PDF file into the WPS interface to start reading, editing, or filling out forms instantly.

Frequently Asked Questions
Why does my JavaScript navigate to the page before the one I wanted?
This typically happens because PDF page numbering in JavaScript is zero-based. If you want to navigate to the 3rd physical page, you must use this.pageNum = 2. Using 3 will take you to the 4th page.
Can I trigger this JavaScript on a button click?
Yes, you can add this JavaScript code to the 'Run a JavaScript' action under the Mouse Up event properties of an interactive button in your PDF form.
Are offline JavaScript actions supported across all PDF readers?
No, while Adobe Acrobat fully supports document-level and field-level JavaScript, many third-party or browser-based PDF readers may restrict or ignore offline JavaScript actions for security reasons.




