PDF Editing Issues

How to Reset a PDF Form and Delete Pages Added from a Template

Chanuka GeekiyanageChanuka Geekiyanage Oct 28, 2026 868 views

Question details

The user needs to reset a dynamic PDF form by clearing filled data and deleting any extra pages that were added from a hidden template.

How to Reset a PDF Form and Delete Pages Added from a Template
Product
Adobe Acrobat PDF
Device & OS
not provided
Scenario
Managing a dynamic PDF form where users can append extra pages from templates, and providing a way to revert the document to its original state.
Observed behavior
The goal is to trigger an action via a reset button that both clears form fields and successfully removes all pages appended after the original document pages.
Before you start

Verify the exact number of original pages in your PDF form, as the JavaScript deletion method relies on a precise page index to avoid deleting the core document.

Solution 1Recommended

Use a JavaScript Action on the Reset Button

Attach a JavaScript code snippet to your reset button to target and delete all pages added beyond the original document length.

PDF page indexing is zero-based. This means the first page is index 0. If your original document has 10 pages, they occupy indexes 0 through 9. Any dynamically added page will start at index 10. The script uses the deletePages method to remove everything from the first appended page to the end of the document.

1
Open Button Properties

Open your PDF form editor, right-click the Reset button, and select 'Properties'.

2
Add a JavaScript Action

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

3
Enter the Deletion Code

Input the following script: this.deletePages(10, this.numPages - 1); Make sure to replace '10' with the actual original page count of your document.

4
Save and Test

Click 'OK' to save the script, close the properties dialog, and test the button to ensure it clears the form and removes the appended pages.

Use a JavaScript Action on the Reset Button
Zero-Based Indexing Reminder: Because the index starts at 0, the number you input as the starting index in the script should equal the total number of original pages (e.g., use 10 for a 10-page document to delete page 11 and beyond).
Manage PDF Pages with Ease

Edit and Manage PDF Pages Visually with WPS Office

If you prefer avoiding complex JavaScript coding, WPS Office provides an intuitive PDF editor. You can visually delete, insert, and rearrange PDF pages with just a few clicks while maintaining full compatibility with standard PDF formats.

  1. 1. Open the PDF File: Launch WPS Office and open your PDF document.
  2. 2. Navigate to Page Management: Click on the 'Page' tab located in the top ribbon menu to view all pages as thumbnails.
  3. 3. Select Pages to Remove: Highlight the extra pages you want to remove, then click the 'Delete Pages' button.
  4. 4. Save the Document: Click 'Save' or press Ctrl+S to confirm the removal of the unwanted pages.
Visually manage PDF pages without writing any JavaScript code.Fully compatible with standard PDF documents and forms.Lightweight, fast, and features a user-friendly ribbon interface.
QA img-9

Frequently Asked Questions

How do I add an additional page from a hidden template in a PDF?

To spawn pages from a hidden template, you typically assign a JavaScript action to a button using the 'getTemplate' method, which duplicates the hidden template and appends it to your active document.

Why is my JavaScript page deletion script not working?

Ensure you are using the correct starting index and that JavaScript is enabled in your PDF viewer. Remember that page indexing starts at zero. Also, verify that the document security settings allow page extraction and deletion.

Will deleting the pages also clear the form fields?

The 'deletePages' script only removes the pages. To clear the remaining form fields on the original pages, you must add a standard 'Reset a form' action to the same button, or include 'this.resetForm();' in your JavaScript.