How to Extract PDF Pages with Custom Suffixes Using JavaScript
Question details
The user wants to extract specific pages from a PDF and save them as separate files with custom name suffixes (e.g., _fill and _cut) using automation.

- Product
- Adobe Acrobat
- Device & OS
- not provided
- Scenario
- Automating the extraction of PDF pages and renaming them systematically using a custom JavaScript menu command.
- Observed behavior
- The goal is to create a custom menu tool that automatically extracts page 1 as a file with a _fill suffix and page 2 with a _cut suffix.
Ensure you have administrative access to the Acrobat JavaScripts folder on your system, and back up your original PDF document before running custom scripts.
Use Acrobat JavaScript to Create a Custom Extraction Tool
Create a trusted JavaScript function to extract pages and assign custom suffixes automatically via the Acrobat Edit menu.
To perform privileged file operations like saving extracted pages directly to your local drive, you must wrap the extraction commands within a trusted function utilizing app.beginPriv() and app.endPriv().
Open your system's file explorer and navigate to the Acrobat 'Javascripts' directory (this can be the program directory under Program Files or your local user AppData directory).
Create a new text document in the folder and change its extension to '.js' (e.g., ExtractWithSuffix.js). Open it with a text editor.
Paste the required JavaScript code that defines the custom menu. Use 'app.addSubMenu' and 'app.addMenuItem' to create the UI buttons, and use 'this.extractPages' to specify the nStart, nEnd, and cPath for the pages.
Save the .js file, close the text editor, then completely quit and restart Adobe Acrobat to load the new add-in.
Open your target PDF, click on the 'Edit' menu on the top toolbar, navigate to 'Custom Tools', and select 'Extract Pages 1-2 with Suffix' to extract and save the renamed pages automatically.

Extract and Manage PDF Pages Effortlessly with WPS Office
Instead of writing complex JavaScript codes, you can easily extract, split, and rename PDF pages using WPS PDF's intuitive graphical user interface.
- 1. Open your PDF: Launch WPS Office and open the PDF document you want to extract pages from.
- 2. Navigate to the Page tools: Click on the 'Page' tab located on the top ribbon to access the document management features.
- 3. Use the Extract feature: Click the 'Extract Page' button to open the extraction dialog box.
- 4. Select pages and save: Choose the specific pages you want to extract, select your desired output directory, and save them. You can easily rename the newly created files directly in your file explorer.

Frequently Asked Questions
Why is my Acrobat JavaScript not extracting the pages?
File operations like extracting and saving pages require elevated privileges. Ensure your script wraps the extractPages method inside app.beginPriv() and app.endPriv() within an app.trustedFunction.
Where can I find the Acrobat JavaScripts folder?
The location varies depending on your operating system and Acrobat version. On Windows, it is typically located at C:\Program Files\Adobe\Acrobat DC\Acrobat\Javascripts or within the user's hidden AppData folder.
How do I change the specific page numbers in the script?
You can modify the nStart and nEnd parameters within the extractPages function. Keep in mind that Acrobat JavaScript uses zero-based numbering, meaning page 1 is designated as nStart: 0.




