PDF Editing Issues

Debug Acrobat JavaScript for Spawned Pages and Delete Buttons

Rana GarciaRana Garcia Nov 18, 2026 870 views

Question details

The user needs to debug an Acrobat JavaScript routine that controls Spawn and Delete buttons on template-generated pages.

Debug Acrobat JavaScript for Spawned Pages and Delete Buttons
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.
Before you start

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.

Solution 1Recommended

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.

1
Reproduce the failure

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.

2
Log page indexes

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.

3
Inspect the button fields

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.

4
Review the deletion logic

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.

5
Retest button visibility

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.

Trace page indexes and button fields after spawning and deletion
Check the field result: A field may have multiple widgets, so its page property can contain more than one page index. Also check for a missing field before reading its properties.
Free Microsoft Office alternative

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.

Open and read PDFs alongside other office documentsCompatible with Microsoft Office formats including DOCX, XLSX, and PPTXFamiliar interface for common document tasksFree, lightweight option for everyday office work
microsoft office alternative - wps office

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.