How to Split a PDF into Separate Invoice Files Using JavaScript
Question details
The user wants to split a bulk PDF containing multiple invoices into separate PDF files, naming each new file according to the specific invoice number found within its pages.

- Product
- Adobe Acrobat
- Device & OS
- not provided
- Scenario
- Processing a large batch PDF file containing multiple invoices of varying page lengths, needing to automatically separate and rename them.
- Observed behavior
- The user needs a programmatic way to identify invoice boundaries, extract the grouped pages, and save them into individual files named automatically based on page content.
Before running any automated scripts, make sure to back up your original bulk PDF file in a secure location. Ensure you have a PDF editor that supports advanced JavaScript execution and document extraction, such as Adobe Acrobat Pro.
Use Acrobat JavaScript to Parse and Extract Invoices
Write and execute a custom JavaScript within Acrobat to identify text patterns (like invoice numbers), extract page ranges, and automatically save them as new files.
This method requires writing a custom script because every invoice layout is unique. The script must iterate through all pages, extract the text, use Regular Expressions to find the invoice number, and group consecutive pages sharing the same invoice number before extracting them into a new file.
Open your bulk PDF invoice file in Adobe Acrobat Pro. Press Ctrl+J (Windows) or Cmd+J (Mac) to open the JavaScript Debugger.
Write a script utilizing the `getPageNumWords` and `getPageNthWord` methods to loop through the text on each page and locate the specific invoice number.
Use a loop to identify where a new invoice number begins. Establish the start and end page index for each invoice to handle invoices that span multiple pages.
Use the `extractPages` method to pull the specific page range, and combine it with the `saveAs` method to save the resulting document using the extracted invoice number as the filename.

Utilize a Third-Party PDF Splitting Plugin
If writing JavaScript is too complex, consider using specialized PDF splitting plugins that feature built-in 'Split by Text' functionalities.
Try WPS Office for Easy PDF and Document Management
Dealing with complex scripts and expensive software for everyday document tasks can be frustrating. WPS Office offers a free, lightweight, and user-friendly alternative to handle your PDFs, Word documents, and spreadsheets efficiently, allowing you to split and manage PDFs visually.

Frequently Asked Questions
Can standard Adobe Acrobat split PDFs by text without JavaScript?
No, out of the box, standard Acrobat features only split PDFs by file size, top-level bookmarks, or a fixed number of pages. Splitting dynamically based on page content, like an invoice number, requires custom JavaScript or a specialized third-party plugin.
How do I handle invoices that have a different number of pages?
Your custom script must be designed to recognize when a new invoice starts by scanning for the next invoice number. It should group all pages between the current invoice number and the next one, ensuring variable-length invoices remain intact.
Is there a completely free tool to automatically split PDFs by invoice number?
Most free tools only offer basic page range splitting. Extracting page text to dynamically name and split files is an advanced automation feature that typically requires premium PDF editors with scripting capabilities or specialized document processing software.




