PDF Editing Issues

Delete PDF Pages After Page Two with Acrobat JavaScript

John WilsonJohn Wilson Nov 19, 2026 868 views

Question details

Configure a reset button to remove all generated PDF pages after the first two pages.

Delete PDF Pages After Page Two with Acrobat JavaScript
Product
Adobe Acrobat
Device & OS
not provided
Scenario
A PDF form contains generated template pages that should be removed when the user clicks a reset button.
Observed behavior
The desired result is to keep pages one and two and delete every subsequent page.
Before you start

Open the PDF in Adobe Acrobat and confirm that it has a button you can edit under Prepare a Form. Check that the document allows page deletion and that Acrobat JavaScript is enabled.

Solution 1Recommended

Add a Delete Pages Action to the Acrobat Reset Button

Use a button JavaScript action to delete page three through the last page while keeping the first two.

Acrobat uses zero-based page indexes, so index 2 is the third page. The condition below avoids attempting a deletion when the document has only two pages or fewer.

1
Open the button properties

In Acrobat, open Prepare a Form, select the reset button, and open its Properties.

2
Add a JavaScript action

On the Actions tab, select Mouse Up as the trigger and Run a JavaScript as the action, then click Add.

3
Enter the deletion script

In the JavaScript editor, enter: if (this.numPages > 2) { this.deletePages(2, this.numPages - 1); }

4
Save and test the button

Confirm the script and button properties, save the PDF, exit form editing, and click the reset button. Verify that only the first two pages remain.

Add a Delete Pages Action to the Acrobat Reset Button
Acrobat permissions: Page deletion may be unavailable in Adobe Acrobat Reader or restricted by document security. The button deletes pages; it does not automatically reset form field values.
Free Microsoft Office alternative

Manage PDF Documents and Office Files with WPS Office

WPS Office is a free, lightweight alternative with a familiar interface and support for common Office formats, making it easy to move between documents. Its PDF tools can help with page management, but they do not replace the Acrobat JavaScript button action described above.

Work with PDF documents and page-management tools; some features may require a subscriptionOpen and edit compatible Microsoft Word, Excel, and PowerPoint formats, including DOCX, XLSX, and PPTXUse a familiar Office-style interface for a smoother transitionAccess a lightweight office suite with a free version
microsoft office alternative - wps office

Frequently Asked Questions

Why does the script start deleting at page index 2?

Acrobat numbers pages from zero in JavaScript: index 0 is page one, index 1 is page two, and index 2 is page three.

What happens if the PDF has only two pages?

The condition this.numPages > 2 prevents the deletePages call, so both pages remain unchanged.

Will the button also clear form fields?

No. The deletePages action removes pages only. Add a separate form-reset action in the button's Actions tab if field values also need to be cleared.

Can this button delete pages in Adobe Acrobat Reader?

Page deletion may not be available in Reader. Test the button in an Acrobat environment that permits page deletion, and check the PDF's security restrictions if it does not work.