Export the Current PDF Page to Word or Excel with Acrobat JavaScript
Question details
The user wants to use an Acrobat JavaScript script to isolate the current page of a PDF and export it directly into a Word or Excel format.

- Product
- Adobe Acrobat
- Device & OS
- not provided
- Scenario
- Automating the extraction of a single viewed PDF page and converting it into an editable document format without processing the entire file.
- Observed behavior
- The user requires a scripted method to handle both page extraction and file conversion sequentially.
Ensure you are using a premium version of Adobe Acrobat, as Acrobat Reader does not support the extraction and conversion methods via JavaScript. Also, verify that the document's security settings permit page extraction.
Use a Two-Step JavaScript Process to Extract and Save
Since Acrobat cannot convert a partial document in one command, you must first extract the page into a temporary document and then save that new document with a conversion parameter.
To achieve this, the script must perform two distinct actions: extracting the currently viewed page to create a new PDF object, and then invoking the save method on that new object using the correct file-conversion handler.
Acrobat JavaScript uses zero-based indexing for pages. You can identify the currently active page using the property `this.pageNum`.
Use the `this.extractPages()` function to pull out the current page. For example: `var newDoc = this.extractPages({nStart: this.pageNum, nEnd: this.pageNum});`
Call the `saveAs()` method on the newly created document object and pass the appropriate conversion ID. Use `"com.adobe.acrobat.docx"` for Microsoft Word or `"com.adobe.acrobat.xlsx"` for Microsoft Excel. Example: `newDoc.saveAs({cPath: "/c/temp/export.docx", cConvID: "com.adobe.acrobat.docx"});`
Clean up the background process by closing the extracted document without saving the PDF version. Use `newDoc.closeDoc(true);`.

Convert PDF Pages to Word or Excel without Coding in WPS Office
If writing JavaScript requires too many security workarounds or you do not have Acrobat Pro, WPS Office provides an incredibly simple, built-in feature to extract and convert specific PDF pages to Word or Excel instantly.
- 1. Open your PDF in WPS Office: Launch WPS Office and open the PDF document containing the page you want to export.
- 2. Select the Conversion Tool: Navigate to the 'Tools' tab and click on either 'PDF to Word' or 'PDF to Excel' depending on your required output format.
- 3. Specify the Page Number: In the conversion dialog box, look for the 'Page Range' option. Select 'Custom' and enter the specific page number you are currently viewing.
- 4. Start the Conversion: Click the 'Convert' button. WPS Office will process only the selected page and immediately open your new, editable Word or Excel file.

Frequently Asked Questions
Why do I get a NotAllowedError when running doc.saveAs()?
Acrobat restricts the saveAs function for security reasons to prevent malicious scripts from writing files to your hard drive automatically. To bypass this, the script must be executed as a privileged context, such as a trusted folder-level script.
What are the exact conversion IDs for Word and Excel in JavaScript?
For Microsoft Word documents (.docx), the identifier is "com.adobe.acrobat.docx". For Microsoft Excel workbooks (.xlsx), it is "com.adobe.acrobat.xlsx".
Do I need Adobe Acrobat Pro to execute this script?
Yes, page extraction (extractPages) and advanced file-conversion scripts require Adobe Acrobat Pro or Standard. The free Acrobat Reader cannot execute these specific document-altering methods.
Can I convert multiple non-continuous pages at once using JavaScript?
Yes, but you will need to extract the pages individually or in specific ranges, compile them into a single temporary PDF document using doc.insertPages(), and then use the saveAs command on that compiled document.




