How to Reset a PDF Form and Delete Pages Added from a Template
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.

- 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.
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.
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.
Open your PDF form editor, right-click the Reset button, and select 'Properties'.
Navigate to the 'Actions' tab, choose 'Run a JavaScript' from the 'Select Action' dropdown, and click 'Add'.
Input the following script: this.deletePages(10, this.numPages - 1); Make sure to replace '10' with the actual original page count of your document.
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.

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. Open the PDF File: Launch WPS Office and open your PDF document.
- 2. Navigate to Page Management: Click on the 'Page' tab located in the top ribbon menu to view all pages as thumbnails.
- 3. Select Pages to Remove: Highlight the extra pages you want to remove, then click the 'Delete Pages' button.
- 4. Save the Document: Click 'Save' or press Ctrl+S to confirm the removal of the unwanted pages.

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.




