Other PDF Issues

How to Email an Extracted PDF Page Using Acrobat JavaScript

Aamir Naveed AkramAamir Naveed Akram Nov 3, 2026 869 views

Question details

The user needs to extract a PDF page using an Acrobat JavaScript button and email the new document, but the script fails because it returns a file path instead of a Document object.

How to Email an Extracted PDF Page with Acrobat JavaScript
Product
Adobe Acrobat
Device & OS
not provided
Scenario
Automating the extraction and emailing of specific PDF pages using a custom JavaScript button.
Observed behavior
The script fails to email the new PDF because the mailDoc method requires a Document object, but the extractPages variable currently holds a file path string.
Before you start

Enable the Acrobat JavaScript Console window before running your script. This will allow you to inspect syntax errors or trace variable types during execution.

Solution 1Recommended

Return a Document Object for the mailDoc Method

Adjust your trusted function so that extractPages returns a Document object instead of saving directly, allowing the mailDoc function to execute properly.

The extractPages method in Acrobat JavaScript cannot simultaneously save a file and return a Document object in a single call. If you configure it to save the file, it returns a file path string. Since the mailDoc function strictly requires a Document object, you must separate the extraction and saving processes.

1
Open your JavaScript code

Access your custom Acrobat JavaScript code and locate your specific trusted function that handles the page extraction.

2
Modify the extractPages call

Change the extractPages parameters to omit the save action. This ensures the method successfully returns a Document object instead of a string.

3
Assign to a variable

Capture the returned Document object by assigning it to a new variable in your script, such as 'var newDoc = extractPages(...)'.

4
Execute mailDoc

Call the mailDoc method directly on the new Document object variable using 'newDoc.mailDoc(...)'. You can then optionally use 'newDoc.saveAs(...)' if you still need to save the file locally.

Return a Document Object for the mailDoc Method
Using the Console Debugger: If the email client still does not open, check the JavaScript Console (Ctrl+J or Cmd+J) to verify that your trusted function is properly returning the Document object to your main script instead of throwing a background error.
Simplify PDF Tasks

Extract and Email PDF Pages Quickly with WPS Office

If writing JavaScript feels overly complex for a simple extraction and email task, WPS PDF provides a built-in, user-friendly interface to extract specific pages and share them instantly without any coding.

  1. 1. Open your PDF document: Launch WPS Office and open the original PDF file from which you want to extract pages.
  2. 2. Access the Extract Page tool: Navigate to the 'Page' tab on the top ribbon and click on the 'Extract Page' tool.
  3. 3. Select pages to extract: Choose the specific pages or page ranges you want to pull out, and select 'Extract as a new PDF'.
  4. 4. Share via Email: Once the newly extracted PDF opens, click the 'Share' or 'Email' button in the top right corner to attach and send it via your default email client.
Extract multiple PDF pages with a single clickDirectly share or email PDFs from the user interfaceFully compatible with Adobe Acrobat PDF formatsLightweight, fast, and free to use
microsoft office alternative - wps office

Frequently Asked Questions

Why does mailDoc fail on my extracted PDF page?

If your extraction script saves the file during the extractPages call, it returns a file path (which is a text string) instead of a Document object. The mailDoc function strictly requires a valid Document object to trigger your email client.

How do I save and email an extracted PDF using JavaScript?

You must perform the actions sequentially rather than in a single call. First, extract the page to generate a Document object. Next, call mailDoc on that object to prepare the email. Finally, call the saveAs method on the same object to save it to your local drive.

Where can I view Acrobat JavaScript errors?

You can view execution errors and debug your scripts using the Acrobat JavaScript Console window. You can easily access this built-in debugging tool by pressing Ctrl+J on Windows or Cmd+J on Mac.