Save Extracted PDF Pages with Adobe Acrobat JavaScript
Question details
The user wants to extract PDF pages with JavaScript, name the resulting files, and open Save As when needed.

- Product
- Adobe Acrobat
- Device & OS
- not provided
- Scenario
- A beginner is automating PDF page extraction and needs to control how the output is saved.
- Observed behavior
- The goal is to save extracted pages under chosen filenames or let the user choose a filename in Save As.
Open the source PDF in desktop Adobe Acrobat and check that its security settings permit page extraction. These examples use Acrobat JavaScript APIs, not browser JavaScript; programmatic file saving may require a trusted or otherwise privileged context.
Extract Pages and Save the New PDF Programmatically
Use Acrobat JavaScript to create a PDF from selected pages and save it under a specified filename.
Page indexes start at 0, so page 1 is index 0. The extractPages() method can also accept an optional cPath to save the extracted pages directly.
Open the PDF in Adobe Acrobat and use a trusted Acrobat JavaScript context appropriate for your workflow.
In your Acrobat JavaScript, create a document from the first page: var extracted = this.extractPages({nStart: 0, nEnd: 0}); Change the indexes to select a different range.
Call extracted.saveAs("/path/to/output.pdf"); using a valid Acrobat device-independent path to an existing folder. Change the filename for each output PDF.

Open the Save As Dialog in Adobe Acrobat
Use this approach when the user should choose the output location and filename manually.
Manage PDF Pages and Office Files with WPS Office
WPS Office is a free, lightweight alternative with a familiar interface for working with PDFs and Office files. Its PDF page tools offer a visual workflow, though WPS does not run or fix Acrobat JavaScript; some PDF features may require a paid plan.

Frequently Asked Questions
Can Acrobat JavaScript fill in the Save As filename?
No. app.execMenuItem("SaveAs") opens the dialog, but the user must fill in its fields. To specify a filename in code, use saveAs() or the cPath option of extractPages() in a permitted context.
How do I extract more than one page?
Set nStart and nEnd in extractPages() to the first and last page indexes. For example, nStart: 0 and nEnd: 2 selects the first three pages.
Why is my programmatic save blocked?
Acrobat may restrict saveAs() or extraction to a file path in the current JavaScript context. Check the PDF permissions and use an appropriate privileged context, such as a configured trusted function.
Can I run this code in a web browser?
No. extractPages(), saveAs(), and app.execMenuItem() in these examples are Acrobat JavaScript APIs. A browser-based workflow requires a different PDF library or service.




