How to Extract PDF Pages Using an Acrobat Pro Button Script
Question details
The user needs to extract a continuous page range or selected nonsequential pages using an Acrobat Pro button script and save them to a specific destination folder.

- Product
- Adobe Acrobat Pro
- Device & OS
- not provided
- Scenario
- Automating the extraction and saving of specific pages from a PDF document using JavaScript assigned to a custom form button.
- Observed behavior
- The user wants to configure a script that successfully isolates the desired pages and manages the file saving process either manually or automatically via predefined paths.
Ensure you have Adobe Acrobat Pro installed and have basic familiarity with the Prepare Form tool, as executing custom JavaScript requires form-editing capabilities.
Use the extractPages Method in a Button Script
Assign a document-level JavaScript utilizing the extractPages method to an interactive button to pull out the specified pages.
Acrobat Pro allows users to attach JavaScript actions to form fields. By using the document-level `this.extractPages(start, end);` method, you can trigger Acrobat to extract a specified range of pages into a new, unsaved PDF document.
It is crucial to remember that Acrobat JavaScript uses zero-based page indexing. This means the first page of your PDF is index 0. If you wish to extract pages 27 through 32, you must subtract one from each page number in your script.
Open your PDF in Acrobat Pro, navigate to the Tools menu, and select 'Prepare Form' to enable form editing.
Click the 'Add a Button' icon in the top toolbar, place the button on your document, and double-click it to open the Button Properties dialog.
Navigate to the 'Actions' tab. Select 'Mouse Up' from the Select Trigger dropdown, choose 'Run a JavaScript' from the Select Action dropdown, and click 'Add'.
In the JavaScript Editor, enter your code. To extract pages 27 through 32, type: `this.extractPages(26, 31);` and click 'OK'.
Close the form editor. Click your newly created button. Acrobat will extract the requested pages into a new PDF window, allowing you to manually save the file.

Extract PDF Pages Easily Without Scripts Using WPS Office
If you need to extract continuous or nonsequential pages but want to avoid writing complex JavaScript and configuring folder-level security bypasses, WPS Office provides an intuitive Page Extraction tool. You can visually select pages and save them directly to any folder in seconds.
- 1. Open the PDF File: Launch WPS Office and open the PDF document from which you want to extract pages.
- 2. Navigate to Page Management: Click on the 'Page' tab located in the top ribbon menu to view the page management tools.
- 3. Select the Extract Tool: Click the 'Extract Page' button to open the extraction dialog box.
- 4. Define the Page Range: Select 'Custom page range' and type your desired pages directly (e.g., '27-32' for sequential, or '27, 32' for nonsequential pages) without worrying about zero-based indexing.
- 5. Extract and Save: Set your destination folder in the output options and click 'Extract' to instantly create and save your new PDF.

Frequently Asked Questions
Why does my Acrobat script extract the wrong page number?
Acrobat JavaScript relies on zero-based indexing. This means page 1 is treated as index 0, page 2 as index 1, and so forth. If you want to extract page 5, you must use the number 4 in your extractPages method.
Can I extract nonsequential pages with a single script command?
The extractPages() method is designed for sequential ranges (start index to end index). To extract scattered, nonsequential pages (like page 27 and page 32), you generally need to extract them individually and then use script methods to merge them, or handle it manually.
Why doesn't my script save the extracted PDF to my folder automatically?
For security reasons, Adobe prevents document-level JavaScript from silently writing files to your local hard drive. To achieve automated saving without a prompt, you must deploy a trusted folder-level script (a .js file placed in Acrobat's internal Privileged folder) that elevates the script's permissions.




