Understanding the Page Position Parameter in Acrobat JavaScript Spawn Method
Question details
The user needs to understand how the page number parameter controls the placement of a new page when spawning a page template in a PDF form via Acrobat JavaScript.

- Product
- Adobe Acrobat
- Device & OS
- not provided
- Scenario
- Writing Acrobat JavaScript to spawn a page template and needing to determine exactly where the new page will be inserted.
- Observed behavior
- Seeking clarification on the nPage zero-based index argument and how it interacts with the bOverlay parameter when generating new pages.
Ensure you have access to the JavaScript debugging console in your PDF editor and a basic understanding of zero-based indexing in programming.
Configure the template.spawn Method Parameters
Use the nPage and bOverlay arguments correctly to define the exact insertion point for your spawned PDF page.
In Acrobat JavaScript, the template.spawn method is used to duplicate a hidden template page within a PDF form. The first argument in this method is nPage, which is a zero-based index that determines where the new page is placed.
Because it is zero-based, index 0 refers to the first page, index 1 refers to the second, and index 2 refers to the third page. The placement also relies heavily on the bOverlay argument to decide if the page should be inserted as a new page or placed over an existing one.
Identify the page number where you want the template to appear. Subtract 1 from the actual page number to get your nPage index. For example, to target the third page, use index 2.
Decide if the spawned content should merge with the target page (set bOverlay to true) or if it should be inserted as a brand-new page immediately after the target index (set bOverlay to false).
Enter your command using the format spawn(nPage, bRename, bOverlay). For instance, running spawn(2, false, false) will insert a fresh page right after the third page of your document.

Manage PDF Pages Visually with WPS Office
While Acrobat JavaScript requires coding to manage page templates, WPS Office features a highly intuitive PDF editor that allows you to visually insert, extract, and manipulate PDF pages and forms with just a few clicks.
- 1. Open your PDF file: Launch WPS Office and open your existing PDF form or document.
- 2. Access the Page tools: Navigate to the 'Page' tab on the top toolbar to reveal all intuitive page management options.
- 3. Insert pages visually: Click 'Insert Page' to instantly add blank pages or import pages from other documents exactly where you need them, bypassing the need for zero-based index calculations.

Frequently Asked Questions
What does a zero-based index mean in Acrobat JavaScript?
A zero-based index means that counting begins at 0 instead of 1. Therefore, page 0 represents the first page of the document, page 1 is the second page, and index n corresponds to the (n+1)th page.
What happens if the bOverlay parameter is set to true?
If bOverlay is true, the spawned template content will be placed over (superimposed onto) the page specified by the nPage index, rather than pushing existing pages down to insert a new blank page.
Can I spawn multiple pages at once using template.spawn?
The template.spawn method only creates one instance of the template at a time. To spawn multiple pages sequentially, you must place the spawn method inside a JavaScript loop, carefully adjusting the nPage index on each iteration.
Where can I find the official reference for the spawn method?
You can find comprehensive details on the spawn method, including exact argument orders and behaviors, within the official Acrobat JavaScript API documentation provided by Adobe.




