Spawn and Remove Multiple PDF Template Pages in Adobe Acrobat
Question details
The user needs a checkbox to add several PDF template pages when selected and remove them when cleared.

- Product
- Adobe Acrobat
- Device & OS
- not provided
- Scenario
- An Acrobat form uses JavaScript to spawn one template page and needs to manage multiple pages instead.
- Observed behavior
- Selecting the checkbox currently spawns one template page rather than several.
In Acrobat, confirm that the form has a template named Section1a and a single-page marker field named Marker1, or substitute your own names. Make sure the pages to be added will remain together immediately after the marker page.
Spawn each template page and delete the contiguous page range
Use this approach when the checkbox controls a fixed group of pages immediately after a marker page.
The example inserts three copies of the same template. It assumes the group is absent before the checkbox is selected and that no other pages are inserted, removed, or reordered within the group before the checkbox is cleared.
Template field renaming can depend on the destination page number. Deleting and respawning pages at reused positions can produce duplicate field names and mirrored values, especially if other spawned pages remain. Test the full workflow and use a form design that keeps generated field names unique.
In Acrobat, open the PDF, select All tools > Prepare a form, and open the properties of the checkbox that will control the pages.
On the Actions tab, choose Mouse Up as the trigger and Run a JavaScript as the action, then select Add. Make sure the action runs after the checkbox value changes.
In the JavaScript editor, enter the following code, replacing the template and marker names if needed: var template = this.getTemplate("Section1a"); var markerPage = this.getField("Marker1").page; if (event.target.value != "Off") { template.spawn(markerPage + 1, true, false); template.spawn(markerPage + 2, true, false); template.spawn(markerPage + 3, true, false); } else { this.deletePages(markerPage + 1, markerPage + 3); } The true argument requests renamed fields; false inserts rather than overlays the pages.
Save the action and PDF, then use Preview in Prepare a form to select and clear the checkbox. Confirm that exactly three pages are added and that only those pages are deleted; repeat the cycle and check that fields do not mirror unexpectedly.

Work with PDFs and Office files in WPS Office
WPS Office is a free, lightweight alternative with a familiar interface for opening PDFs and working with Office files. Its format support helps you move existing documents into WPS; it does not fix or replace Acrobat's template-spawning JavaScript.

Frequently Asked Questions
How do I add a different number of template pages?
In the checkbox JavaScript action, add or remove template.spawn calls with consecutive page positions. Update the ending page in this.deletePages so it matches the last spawned page.
Why do fields on spawned pages show the same value?
Fields with duplicate names can mirror one another. Acrobat's template renaming can reuse names when pages are spawned at previously used positions, so inspect the field names in Prepare a form and design the workflow to keep them unique.
Can I delete the pages if users have rearranged them?
Not safely with the fixed range in this example. this.deletePages removes the pages currently at those positions, so the form needs a way to identify and track its generated pages before deleting them.
Will this checkbox action work in every PDF viewer?
No. PDF viewers differ in their support for Acrobat JavaScript and page modification. Test the saved form in the Acrobat environment where it will be used.




