Other PDF Issues

How to Delete Multiple Pages in PDF with Acrobat JavaScript

Nimra MalikNimra Malik Nov 5, 2026 870 views

Question details

The user needs to delete a specific range of spawned pages (pages 4 to 7) in a PDF using Acrobat JavaScript, but the current code only deletes one page per click.

How to Delete Multiple Pages with Acrobat JavaScript
Product
Adobe Acrobat
Device & OS
not provided
Scenario
Automating the deletion of dynamically spawned templates in a PDF form using custom JavaScript.
Observed behavior
The script deletes only one page per click because it calls deletePages repeatedly in a way that is disrupted by changing dynamic page indexes.
Before you start

Ensure your PDF document does not have security restrictions preventing page extraction or deletion, and save a backup copy of your PDF before running custom JavaScript.

Solution 1Recommended

Use the deletePages Method for a Specific Page Range

Pass the start and end page indexes into a single this.deletePages() call to remove the entire range at once without indexing conflicts.

When deleting multiple pages individually in a loop, the page indexes dynamically shift after each deletion, which causes standard loops to skip pages. By defining a range in a single command, the software handles the index shifting automatically.

Acrobat JavaScript uses zero-based indexing, meaning Page 1 is index 0. To delete the 4th through the 7th pages of your document, you need to target indexes 3 through 6.

1
Open JavaScript Editor

Open your PDF form in Adobe Acrobat and navigate to the button or form field's Action properties where your current JavaScript is stored.

2
Apply the Range Deletion Command

Replace your existing looping deletion script with the single range command: this.deletePages(3, 6);

3
Include Explicit Document Reference

Ensure you include the explicit document reference ('this.') in your function call so the script executes securely within the current document's context.

4
Test the JavaScript

Save your form and click the trigger button to verify that all the intended spawned pages are removed simultaneously.

Use the deletePages Method for a Specific Page Range
Zero-based Indexing Reminder: Always subtract 1 from your actual document page numbers when using this.deletePages(nStart, nEnd) to account for JavaScript's 0-based indexing system.
Manage PDF Pages Visually

Delete Multiple PDF Pages Instantly with WPS Office

If writing and debugging JavaScript feels overly complex for simple page removal, WPS PDF provides a visual Page Management tool where you can select, organize, and delete multiple PDF pages in just a few clicks—no coding required.

  1. 1. Open your PDF: Launch WPS Office and open your target PDF document.
  2. 2. Access Page Management: Click on the 'Page' tab located in the top navigation ribbon to switch to the visual thumbnail view.
  3. 3. Select Multiple Pages: Hold down the 'Ctrl' key and click to select non-consecutive pages, or click and drag your cursor to highlight a continuous range of pages.
  4. 4. Delete Instantly: Click the 'Delete' icon (represented by a trash can) on the toolbar to remove all selected pages at once.
Select and delete multiple pages visually without needing to write or debug JavaScript.Highly compatible with all standard PDF files, including Adobe Acrobat created documents.Lightweight software with an intuitive, ribbon-based page management interface.
microsoft office alternative - wps office

Frequently Asked Questions

Why does my Acrobat JavaScript loop fail to delete all intended pages?

Adobe Acrobat uses dynamic page indexing. When you delete the page at index 3, the page previously at index 4 immediately shifts down to become the new index 3. A standard ascending loop will effectively skip pages due to this shift. Using this.deletePages(start, end) avoids this problem entirely.

Can I delete non-consecutive pages using Acrobat JavaScript?

Yes, but you must delete them in reverse order (from the highest index to the lowest). This ensures that deleting a page at the end of the document doesn't shift the indexes of the remaining pages you intend to delete earlier in the document.

Is there a way to delete multiple pages without using JavaScript at all?

Yes. In standard PDF editors like WPS PDF, you can simply open the Page Thumbnails panel, hold Ctrl (or Command on Mac) to select multiple specific pages, and press the Delete key or click the Delete icon to remove them visually.