PDF Editing Issues

How to Delete Every 5th and 6th Page Using Acrobat JavaScript

Steve KSteve K Nov 5, 2026 870 views

Question details

The user needs to automate deleting the 5th and 6th pages of every 6-page group in a 149-group PDF document.

How to Delete Every Fifth and Sixth Page with Acrobat JavaScript
Product
Adobe Acrobat
Device & OS
not provided
Scenario
Automating repetitive page deletion tasks in a large PDF document to remove specific repeating pages.
Observed behavior
The user wants to implement an Acrobat JavaScript snippet via the Action Wizard that accurately removes the targeted pages without disrupting the document's page indexing.
Before you start

Always duplicate your PDF file and work on the copy before executing JavaScript deletions, as script actions generally cannot be undone.

Solution 1Recommended

Use a Reverse-Loop JavaScript Snippet

Execute a reverse-iteration loop in Acrobat to securely delete specific pages while keeping preceding page indexes intact.

When deleting pages programmatically in Acrobat, you must start from the end of the document and move backward. If you delete from the beginning, the index numbers of all subsequent pages will shift backward, causing the script to miscalculate and delete the wrong pages.

1
Open the JavaScript Debugger or Action Wizard

In Adobe Acrobat Pro, open the Action Wizard from the Tools menu to apply a script to the document, or simply press Ctrl+J (Windows) or Cmd+J (Mac) to open the JavaScript Debugger.

2
Input the reverse-loop code

Type or paste the following code into the console: for (var p = this.numPages - 1; p > 0; p -= 6) { this.deletePages(p - 1, p); }

3
Execute the script

Run the script. This loop iterates backwards in intervals of 6, targeting the 5th and 6th pages of each group. Because Acrobat page indexes start at 0, it deletes indexes 'p-1' and 'p' securely.

Use a Reverse-Loop JavaScript Snippet
Zero-Based Indexing: Remember that Acrobat JavaScript counts the first page as index 0. Always verify your starting parameters on a short test document before applying it to hundreds of pages.
Free Microsoft Office alternative

Manage and Organize PDFs Easily with WPS Office

While advanced JavaScript execution is unique to Acrobat, WPS Office offers a highly intuitive visual interface for deleting, extracting, and reordering PDF pages, making standard document management easily accessible without needing to write custom code.

Seamlessly organize, delete, or extract PDF pages with a user-friendly visual interface.Fully compatible with standard PDF files and Microsoft Office document formats.Lightweight and fast, requiring significantly fewer system resources than heavy enterprise software.Feature-rich suite including seamless PDF-to-Word conversions, text editing, and annotations.
microsoft office alternative - wps office

Frequently Asked Questions

Why do we iterate backward when deleting pages with JavaScript?

Iterating backward ensures that when a page is deleted, the index numbers of the remaining pages that appear earlier in the document do not change. This prevents the script from accidentally shifting indices and deleting the wrong pages.

Can I use this script for different page group sizes?

Yes. To modify the script for a different group size, change the loop interval 'p -= 6' to match your new total group size, and adjust the 'this.deletePages()' parameters to target the correct zero-indexed pages within that specific group.

Can I undo page deletions made via Acrobat JavaScript?

No, scripts executed via the JavaScript Debugger or Action Wizard typically cannot be undone using the standard 'Undo' command. You should always run destructive scripts on a backup copy of your PDF.