PDF Editing Issues

How to Extract Non-Sequential PDF Pages Using JavaScript in Acrobat

Natalie TaylorNatalie Taylor Nov 24, 2026 868 views

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.

How to Extract Non-Sequential PDF Pages Using JavaScript in Acrobat
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.
Before you start

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.

Solution 1Recommended

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.

1
Define the page array

In your Acrobat JavaScript console or script, create an array containing the zero-based indexes of the non-sequential pages you wish to extract.

2
Create a new document

Use the app.newDoc() function to generate a blank destination PDF document where the extracted pages will be placed.

3
Loop through the pages

Set up a standard 'for' loop to iterate through your predefined array of page numbers.

4
Insert pages

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.

Create a New Document and Insert Pages via Loop
Zero-based Indexing: Remember that page numbers in Acrobat JavaScript are zero-based. For example, to extract page 5 of your document, you must reference it as page 4 in your script.
Extract PDF Pages Easily

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. 1. Open your PDF: Launch WPS Office and open the PDF document you want to extract pages from.
  2. 2. Navigate to the Page tab: Click on the 'Page' tab located on the top toolbar to view all pages as thumbnails.
  3. 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. 4. Extract and save: Click the 'Extract Pages' button in the toolbar, confirm your selection, and save the newly generated PDF document.
Visual page selection interface without the need for scriptingEasily extract, delete, and merge PDF pages in a few clicksFully compatible with standard Adobe PDF document formatsLightweight, fast, and runs smoothly on PC and mobile devices
microsoft office alternative - wps office

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.