PDF Conversion Issues

How to Extract and Export the First Two PDF Pages to Excel with JavaScript

Algirdas JasaitisAlgirdas Jasaitis Nov 2, 2026 869 views

Question details

The user wants to isolate the first two pages of multiple PDF files and export the shortened documents to Excel using an automated JavaScript or Action workflow.

How to Extract and Export the First Two PDF Pages to Excel with JavaScript
Product
Adobe Acrobat
Device & OS
not provided
Scenario
Batch processing multiple PDFs to retain only the first two pages and converting the specific retained data into Excel spreadsheets.
Observed behavior
Instead of manually extracting pages for each file, the user requires a script to automatically remove unwanted pages and trigger the Excel export command.
Before you start

Before running automated JavaScript on your PDF files, ensure you have a backup of the original documents in a separate folder, as automated page deletion scripts can permanently modify files if saved accidentally.

Solution 1Recommended

Use Acrobat JavaScript to Delete Unwanted Pages and Export

Instead of creating a temporary extracted file, you can write a script to delete all pages after the second page and then save the file directly in Excel format.

In Acrobat, it is often more efficient to delete the unwanted pages from the current document rather than spawning a new document and copying pages over. Once the extra pages are deleted, you can call the SaveAs function to export the remaining document as an Excel file.

1
Open the Action Wizard

In Adobe Acrobat Pro, navigate to 'Tools' and select 'Action Wizard'. Click on 'New Action' to create a new batch process.

2
Add the Execute JavaScript tool

Under the 'Choose tools to add' panel, find 'More Tools' and click 'Execute JavaScript'. Add it to your Action steps.

3
Insert the page deletion script

Open the JavaScript editor and paste the following code to delete pages 3 and beyond: if (this.numPages > 2) { this.deletePages({nStart: 2, nEnd: this.numPages - 1}); this.dirty = false; }

4
Add the export command

Below the deletion code, add the command to save the file as an Excel spreadsheet: this.saveAs(this.path.replace(".pdf", ".xlsx"), "com.adobe.acrobat.xlsx");

5
Run the Action

Save the Action, select the folder containing your target PDFs, and run the Action to process the files in bulk.

Use Acrobat JavaScript to Delete Unwanted Pages and Export
Preventing Overwrites: Setting 'this.dirty = false;' ensures that Acrobat does not prompt you to save the changes to the original PDF, leaving your source file intact.
Easy PDF to Excel Conversion

Extract PDF Pages and Convert to Excel Easily with WPS Office

Skip the complex JavaScript coding. WPS Office provides a user-friendly interface to instantly extract specific PDF pages and convert them directly to Microsoft Excel format without needing any programming knowledge.

  1. 1. Open your PDF: Launch WPS Office and open the PDF document you want to convert.
  2. 2. Select PDF to Excel: Navigate to the 'Tools' tab on the top ribbon and select 'PDF to Excel'.
  3. 3. Set the page range: In the conversion dialog box, specify the 'Page Range' as '1-2' to only process the first two pages.
  4. 4. Convert and save: Click the 'Convert' button. WPS Office will instantly generate an Excel file containing only the data from the first two pages.
Select custom page ranges (like pages 1-2) for extractionDirectly convert PDF tables to editable Excel formatsFully compatible with Microsoft Office formats (.xlsx)User-friendly interface requires no coding knowledge
microsoft office alternative - wps office

Frequently Asked Questions

Can I use this JavaScript in free PDF readers?

No, executing advanced document-modifying JavaScript and utilizing batch Actions typically requires a premium PDF editor like Adobe Acrobat Pro.

Why delete pages instead of extracting them in the script?

Deleting unwanted pages from the current document and exporting the result is computationally simpler in Acrobat JavaScript than creating a new blank document and moving pages over one by one.

How do I prevent the script from saving over my original PDF?

You can set 'this.dirty = false;' in your JavaScript right after the page deletion. This tricks the application into thinking the document hasn't been modified, allowing you to close it safely without overwriting the original file.