PDF Editing Issues

How to Dynamically Insert and Hide PDF Page Templates in Adobe Acrobat

Maira MehtabMaira Mehtab Nov 24, 2026 868 views

Question details

The user needs to dynamically insert a template page right after a specific page when a checkbox is selected, and automatically delete it when the checkbox is unchecked.

How to Dynamically Insert and Hide PDF Page Templates in Adobe Acrobat
Product
Adobe Acrobat
Device & OS
not provided
Scenario
Designing an interactive PDF form where pages dynamically appear or disappear based on user checkbox selections.
Observed behavior
Instead of unhiding a template at the very end of the document, the user wants the template to spawn directly after the active page, and requires a script to securely remove the page upon deselection.
Before you start

Ensure you have Adobe Acrobat Pro installed and your interactive form's template pages are correctly configured in the Page Templates menu, as this process requires writing advanced custom JavaScript actions.

Solution 1Recommended

Use JavaScript to Spawn and Delete Template Pages

Apply a custom JavaScript action to the form's checkbox to handle both inserting the template at a specific page index and deleting it when deselected.

When you simply unhide a template page, Adobe Acrobat automatically places it at the very end of the file. To insert the template immediately after the current page, you need to use the Acrobat JavaScript `Template.spawn()` method. To reverse this action and make the page disappear, the `this.deletePages()` method is used to cleanly remove the newly spawned page.

1
Open Prepare Form tool

Open your interactive PDF document in Adobe Acrobat and navigate to the 'Prepare Form' tool from the right-hand pane.

2
Access checkbox properties

Right-click the checkbox you want to use as a trigger for the dynamic page and select 'Properties'.

3
Add a JavaScript action

Navigate to the 'Actions' tab. Select 'Mouse Up' as the trigger, choose 'Run a JavaScript' from the Select Action dropdown, and click 'Add'.

4
Write the spawn and delete script

Enter the script logic: `if(event.target.value != 'Off') { this.getTemplate('MyTemplate').spawn(event.target.page + 1, true, false); } else { this.deletePages(event.target.page + 1); }`. Replace 'MyTemplate' with the exact name of your hidden page template.

5
Save and test the form

Click 'OK' to save the script, close the properties window, exit form editing mode, and test the checkbox to verify the page is dynamically inserted and deleted.

Use JavaScript to Spawn and Delete Template Pages
Page Indexing: Keep in mind that JavaScript arrays are zero-indexed, meaning the first page is page 0. Using `event.target.page + 1` precisely targets the slot immediately following the current page.
Professional PDF Editor

Easily Manage PDF Pages and Forms with WPS Office

While scripting dynamic form actions requires advanced coding in Adobe Acrobat, WPS Office provides an intuitive, highly visual PDF editor. You can easily insert, extract, delete, and organize PDF pages manually, as well as fill out interactive forms without writing complex JavaScript code.

  1. 1. Open your PDF document: Launch WPS Office and open your existing PDF file or interactive form.
  2. 2. Navigate to the Page tab: Click on the 'Page' tab on the top ribbon to access visual page management tools.
  3. 3. Insert new pages: Click 'Insert Page' to easily add a blank page or import a page from another PDF document exactly where you need it.
  4. 4. Delete unwanted pages: To remove unnecessary pages quickly, simply select the target page thumbnail and click the 'Delete' button.
Visual drag-and-drop PDF page management for easy document organizationSeamless compatibility with standard PDF interactive forms and annotationsExcellent compatibility with Microsoft Office formats (Word, Excel, PowerPoint) and Adobe PDFLightweight, lightning-fast application that uses minimal system resources
microsoft office alternative - wps office

Frequently Asked Questions

Why does my unhidden PDF template always appear at the end of the document?

By default, Adobe Acrobat appends newly unhidden template pages to the very end of the PDF file. To place them exactly where you want, you must either use the `movePage` command after unhiding or use the `Template.spawn()` method to insert them dynamically at a specific index.

Can I use dynamic template spawning in Adobe Reader?

Dynamic page spawning typically requires Adobe Acrobat Pro to author and set up. However, users viewing the document with the free Adobe Reader can trigger the spawned pages only if the original creator saved the document with 'Reader Enable Usage Rights' applied.

How do I remove a spawned page using a checkbox?

You can assign a JavaScript action to the checkbox's 'Mouse Up' event that detects if the checkbox is unchecked (e.g., ensuring its value is 'Off'). Once detected, the script should run `this.deletePages(event.target.page + 1)` to specifically remove the spawned page.

Does using deletePages affect the original hidden template?

No. The `this.deletePages()` command only removes the visible, active page at the specified index that was created. Your original hidden template remains safely stored in the document's background data, ready to be spawned again.