How to Automatically Add Unique Numbers to PDF Pages from Excel
Question details
The user needs to insert a sequence of unique identifiers from an Excel spreadsheet onto individual pages of a PDF document before printing.

- Product
- PDF Editors
- Device & OS
- not provided
- Scenario
- Assigning unique tracking numbers or identifiers from a predefined list to each page of a multi-page PDF.
- Observed behavior
- Standard PDF editors cannot directly pull data from Excel workbooks to stamp pages natively, requiring a data export and scripting workaround.
Ensure your Excel list of identifiers exactly matches the total number of pages in your PDF document, and save a backup copy of your original PDF before running any scripts.
Export Excel to Plain Text and Use PDF JavaScript
Since most PDF editors cannot read Excel files directly, you need to convert your list to a plain text file and use custom JavaScript to stamp the numbers onto the PDF.
Advanced PDF editors support document-level JavaScript, which can be used to read external text files. By converting your Excel data into a text file, you bridge the compatibility gap and automate the numbering process.
Open your Excel file, ensure all identifiers are listed in a single column without empty rows, and go to File > Save As. Choose 'Text (Tab delimited)' or 'CSV (Comma delimited)' to save the data as plain text.
Open your target multi-page PDF in a PDF editor that supports advanced scripting, such as Adobe Acrobat Pro.
Navigate to the JavaScript console (in Acrobat, go to Tools > JavaScript > Document JavaScripts). Input a custom script designed to read the plain-text file line by line and insert the variables as text fields, watermarks, or comments on the corresponding pages.
Once the script finishes executing, review the document to verify that each page displays the correct tracking number. Save the modified PDF and proceed to print.

Easily Add Unique Numbers to Documents with WPS Office
Instead of dealing with complex JavaScript, you can seamlessly integrate your Excel data into your documents using WPS Office's built-in Mail Merge feature, and then export the final result back to PDF.
- 1. Convert PDF to Word: Open your PDF in WPS Office and use the 'PDF to Word' tool in the Tools tab to convert your document into an editable Word file.
- 2. Prepare Your Spreadsheet: Ensure your tracking numbers or unique identifiers are saved in a WPS Spreadsheet (.xlsx) with a clear column header.
- 3. Initiate Mail Merge: In your newly converted Word document, navigate to the 'References' or 'Mailings' tab, click 'Open Data Source', and select your spreadsheet.
- 4. Insert Merge Field: Place your cursor exactly where you want the number to appear on the page, and click 'Insert Merge Field' to insert the tracking number column.
- 5. Export to PDF: Click 'Merge to New Document' to generate all the uniquely numbered pages, then go to Menu > Export to PDF to save the final document for printing.

Frequently Asked Questions
Can I use the standard 'Add Header & Footer' tool to add Excel numbers?
No, the standard 'Add Header & Footer' tool in most PDF editors only allows you to add sequential page numbers (e.g., 1, 2, 3) or static text. It cannot automatically pull a specific, pre-defined list of non-sequential identifiers from an external Excel file.
Is there a way to add unique identifiers without using JavaScript in my PDF editor?
Yes. The easiest no-code workaround is to convert your PDF into a Word document, use the Mail Merge feature to link your Excel data, and then export the merged document back to a PDF format.
What format should my Excel list be in before importing via a script?
If you are using custom JavaScript in your PDF editor, it is highly recommended to save your Excel data as a plain Text (Tab-delimited) or CSV (Comma delimited) file, as PDF JavaScript cannot natively parse raw .xlsx or .xls workbook files.




