PDF Editing Issues

How to Spawn a PDF Template After the Current Page in Adobe Acrobat

John WilsonJohn Wilson Nov 24, 2026 869 views

Question details

The user needs to programmatically spawn a hidden PDF page template directly after their current active page using JavaScript.

How to Spawn a PDF Template After the Current Page in Adobe Acrobat
Product
Adobe Acrobat
Device & OS
not provided
Scenario
Using JavaScript to insert a hidden template dynamically based on the user's active page index without causing page conflicts.
Observed behavior
The user wants to use a script utilizing dynamic variables (like this.pageNum) to insert the spawned template right after the active page without accidentally overwriting existing content.
Before you start

Before running JavaScript to modify PDF pages, ensure your document has a named, hidden template page already set up and that you have a backup of your original file to prevent accidental data loss.

Solution 1Recommended

Use JavaScript to Spawn the Template Based on Page Number

Utilize the getTemplate() and spawn() methods, passing this.pageNum + 1 to safely insert the template immediately after the current page.

Instead of hardcoding the page index or relying on event.target.page (which can return an array if there are multiple copies of a field), you can dynamically target the location using this.pageNum.

To place the new page immediately following the active page, add 1 to the current page number. Be careful not to spawn exactly at this.pageNum unless you have configured field renaming, as it can cause overlapping.

1
Open the JavaScript Console or Button Action

In Adobe Acrobat, go to 'Tools' > 'JavaScript' and select 'Document JavaScripts', or add a 'Run a JavaScript' action to a form button.

2
Retrieve the Template

Declare a variable to get your hidden template using the command: var template = this.getTemplate('YourTemplateName');

3
Spawn the Template

Execute the spawn command targeting the next page index: template.spawn(this.pageNum + 1, false, false);

4
Test the Script

Run the script from different pages in your PDF to ensure the template is dynamically inserted right after your current viewing position.

Use JavaScript to Spawn the Template Based on Page Number
Zero-based Indexing: Remember that PDF pages use a zero-based index. The first page is always 0. The this.pageNum variable correctly accounts for this when retrieving your current location.

Manage PDF Pages and Templates Easily with WPS Office

For users who prefer a straightforward visual interface over writing JavaScript, WPS Office provides powerful PDF editing tools. You can easily insert, extract, and manage PDF pages or templates without any coding.

  1. 1. Open Your PDF in WPS Office: Launch WPS Office and open your PDF document using the built-in WPS PDF editor.
  2. 2. Navigate to the Page Tab: Click on the 'Page' tab in the top ribbon to access the visual page management tools.
  3. 3. Insert a New Page: Select the page after which you want to add content, click 'Insert', and choose whether to insert a blank page or append a page from another PDF file.
  4. 4. Organize Your Document: Drag and drop pages in the thumbnail pane to reorder them exactly as needed without relying on complex JavaScript.
Visually insert blank pages or template pages with a few clicks.Fully compatible with standard PDF formats and interactive forms.Lightweight application with a user-friendly interface.Edit PDF text, images, and pages without writing JavaScript.
microsoft office alternative - wps office

Frequently Asked Questions

Why is my spawned PDF template overwriting the current page?

If you pass this.pageNum as the page index in the spawn() method and do not rename the fields (using the bRename parameter), the spawned page may overlay or conflict with the current page. Passing this.pageNum + 1 safely places it after the current page.

Can I use event.target.page to determine where to spawn a PDF template?

It is generally not recommended. If your PDF has multiple copies of a field with the same name, event.target.page will return an array of page numbers rather than a single integer, causing your spawn script to fail. Use this.pageNum instead.

Do PDF page numbers in JavaScript start at 1?

No, PDF page indexes in JavaScript are zero-based. The first page is index 0. Therefore, this.pageNum returns 0 for the first page, and adding 1 correctly targets the second page position.