Debug Acrobat JavaScript for Spawned Pages and Delete Buttons
Question details
The user needs to debug an Acrobat JavaScript routine that controls Spawn and Delete buttons on template-generated pages.

- Product
- Adobe Acrobat
- Device & OS
- not provided
- Scenario
- A PDF uses a template to spawn pages. Spawned pages should show both Spawn and Delete buttons, while the original page should show only Spawn.
- Observed behavior
- The routine fails when more than two pages are spawned; the exact failure and document structure are not provided.
Identify the template, the original page, the button field names, and the script attached to each button. Open Acrobat's JavaScript console or debugger so you can inspect page indexes and field properties after each action.
Trace page indexes and button fields after spawning and deletion
Use this approach to find which page or field the script targets when more than two pages are spawned.
Acrobat page indexes are zero-based, and deleting a page shifts the indexes of later pages. The current page, this.pageNum, is not necessarily the page that was just spawned.
The exact script and document structure are needed before a reliable code correction can be provided.
Open the PDF in Acrobat and use its Spawn button to create at least three pages. Note when the buttons or deletion behavior stop matching the intended result.
In the JavaScript console or debugger, inspect this.pageNum, this.numPages, and the script's pg value before and after spawning or calling this.deletePages(). Check that pg, pg + 1, and pg + 2 point to the intended pages.
Use this.getField with each actual Spawn and Delete field name, then inspect the field's page property. Check the names created after spawning, since template-spawn settings can change field names.
Find each this.deletePages() call in the button script and verify its target immediately before deletion. If deleting multiple verified pages, account for shifting indexes; deleting from the highest index downward can prevent earlier deletions from shifting later targets.
Spawn and delete pages again using the PDF's buttons. Confirm that the original page shows only Spawn and each spawned page shows both Spawn and Delete.

Use WPS Office for everyday PDF and document work
WPS Office is a free, lightweight alternative with a familiar interface for working with PDFs and Office files. Its format compatibility helps make migration straightforward, though it does not debug Acrobat JavaScript.

Frequently Asked Questions
Why do page indexes change after deleting a page?
Acrobat uses zero-based page indexes. After this.deletePages() removes a page, later pages move down, so recalculate or recheck their indexes before the next deletion.
Does this.pageNum identify the page that was just spawned?
Not necessarily. this.pageNum refers to the current page. Inspect the spawn operation and log page indexes in Acrobat's JavaScript console to identify the new page.
How can I check which page contains a button?
In Acrobat's JavaScript console, retrieve the button with this.getField using its actual field name and inspect its page property. A field with multiple widgets can have more than one page index.
Why might a button field not be found after spawning?
Template-spawn settings can affect the names of generated fields. Inspect the spawned fields' actual names and check that this.getField returns a field before using its properties.




