How to Extract Non-Sequential PDF Pages Using JavaScript in Acrobat
Question details
The user wants to extract multiple non-consecutive pages from an existing PDF and combine them into a single new PDF document using Adobe Acrobat JavaScript.

- Product
- Adobe Acrobat
- Device & OS
- not provided
- Scenario
- Automating the extraction of specific, non-sequential pages from a large PDF document using scripting.
- Observed behavior
- The native this.extractPages() method does not accept arrays for non-sequential pages, preventing users from performing the extraction in a single command.
Ensure you have Adobe Acrobat Pro or Standard installed, as the free Adobe Acrobat Reader does not support executing advanced document-level JavaScript for page manipulation.
Create a New Document and Insert Pages via Loop
Programmatically create a blank PDF and insert the desired non-sequential pages one by one using a JavaScript loop.
Since the extractPages method only accepts sequential page ranges, the most reliable approach is to instantiate a new document and pull in the specific pages you need one at a time.
In your Acrobat JavaScript console or script, create an array containing the zero-based indexes of the non-sequential pages you wish to extract.
Use the app.newDoc() function to generate a blank destination PDF document where the extracted pages will be placed.
Set up a standard 'for' loop to iterate through your predefined array of page numbers.
Inside the loop, use the this.insertPages() method on the new document to pull each specific page from the source document, appending it sequentially to the new file.

Save a Copy and Delete Unwanted Pages
Save a duplicate of the current PDF and use a script to iteratively remove the pages you do not want to keep.
Extract Non-Sequential PDF Pages Easily with WPS Office
If writing JavaScript loops is too complex, WPS Office provides an intuitive visual interface to select and extract non-consecutive pages from your PDF into a new document without any coding.
- 1. Open your PDF: Launch WPS Office and open the PDF document you want to extract pages from.
- 2. Navigate to the Page tab: Click on the 'Page' tab located on the top toolbar to view all pages as thumbnails.
- 3. Select non-sequential pages: Hold down the 'Ctrl' key on your keyboard and click on the specific pages you wish to extract to highlight them.
- 4. Extract and save: Click the 'Extract Pages' button in the toolbar, confirm your selection, and save the newly generated PDF document.

Frequently Asked Questions
Why does this.extractPages() fail when passing an array of non-sequential pages?
The extractPages() method in Acrobat JavaScript is explicitly designed to accept an nStart and nEnd parameter for a contiguous, sequential range of pages. It does not possess the native capability to parse an array of disjointed page numbers.
Are page numbers in Acrobat JavaScript exactly the same as the document pages?
No, Acrobat JavaScript utilizes a zero-based indexing system for document pages. This means the first page is index 0, the second page is index 1, and so on. You must adjust your arrays accordingly when scripting.
Can I run page extraction JavaScript in the free Adobe Reader?
No, methods such as insertPages, deletePages, and extractPages are considered restricted methods. They require Adobe Acrobat Standard or Pro to execute successfully and will fail or throw security exceptions in Adobe Reader.
Why is it recommended to delete pages backward in a loop?
When you delete a page from a PDF, the indexes of all subsequent pages shift down by one. If you loop forward, you will skip pages or delete the wrong ones. Looping backward ensures the indexes of the remaining pages are unaffected.




