PDF Editing Issues

How to Automate Custom PDF Page Numbers from File Names

Olivia MillerOlivia Miller Nov 3, 2026 869 views

Question details

The user needs to automate the insertion of custom page numbers into multiple separate PDF files, where each page number includes a specific prefix (like A1-1) extracted directly from the document's file name.

How to Automate Custom PDF Page Numbers from File Names
Product
Adobe Acrobat
Device & OS
not provided
Scenario
Batch processing multiple PDF documents to automatically append a dynamic prefix, derived from the file name, to the standard page numbers in the header or footer.
Observed behavior
Standard page numbering tools do not automatically pull file names as prefixes; the process requires advanced tools like Action Wizard and JavaScript to extract the file name and loop through the pages.
Before you start

Before running any automated batch scripts or Action Wizards, ensure you have created a backup folder containing the original, unmodified PDF files to prevent accidental data loss or formatting errors.

Solution 1Recommended

Use Acrobat Action Wizard with Custom JavaScript

Utilize Adobe Acrobat's Action Wizard combined with a custom JavaScript snippet to automatically extract the file name, isolate the desired prefix, and insert it alongside the page number in the header or footer.

Because standard header and footer tools only allow for static text or simple page counts, dynamically pulling the file name requires a script. By creating an Action Wizard workflow, you can apply this script to hundreds of files at once.

1
Open the Action Wizard

Launch Adobe Acrobat Pro, go to the 'Tools' menu, and select 'Action Wizard'.

2
Create a New Action

Click on 'New Action' in the toolbar. In the 'Files to be Processed' section, select the folder containing the separate PDF files you want to number.

3
Add the JavaScript Execution Step

Under the 'Choose tools to add' panel, expand 'More Tools' and select 'Execute JavaScript'. Click the '+' button to add it to your action steps on the right.

4
Write the Automation Script

Click 'Specify Settings' on the JavaScript step. Input a script that uses 'document.documentFileName' to extract the name, splits the string to get your section prefix (e.g., 'A1'), and loops through 'this.numPages' to add a custom text field or watermark to each page containing the formatted number (e.g., 'A1-1').

5
Save and Run the Action

Save your newly created Action with a recognizable name. Click on it from the Action Wizard list and press 'Start' to process all files in your selected folder automatically.

Use Acrobat Action Wizard with Custom JavaScript
JavaScript Knowledge Required: Writing the exact JavaScript requires familiarity with the Acrobat API. If you are unfamiliar with coding, you may need to consult the Acrobat Developer Forum for a specific script tailored to your exact file naming convention.

Add Custom Page Numbers Easily with WPS PDF

If you do not want to deal with complex JavaScript coding to add page numbers, WPS PDF offers a highly intuitive Header and Footer tool. While fully automated file-name extraction requires scripting, WPS PDF lets you quickly configure and batch-apply custom prefixes and dynamic page numbers to your documents in just a few clicks.

  1. 1. Open Your Document in WPS PDF: Launch WPS Office, select the PDF module, and open the PDF file you wish to number.
  2. 2. Access Header and Footer Tools: Navigate to the 'Edit' or 'Insert' tab on the top ribbon and select 'Header and Footer'.
  3. 3. Add a Custom Prefix: Click 'Add Header and Footer'. In the configuration window, manually type your desired prefix (e.g., the file name 'A1-') into the desired section (Left, Center, or Right).
  4. 4. Insert the Page Number: Next to your custom prefix, click the 'Insert Page Number' button to add the dynamic page count.
  5. 5. Apply Settings: Review the preview window to ensure the format looks like 'A1-1', then click 'OK' to apply the custom page numbers to the document.
Easily configure custom prefixes and page numbering formats without writing any code.Seamlessly view, edit, and save PDF files with full Adobe Acrobat format compatibility.Lightweight and user-friendly interface designed for straightforward document management.Cost-effective alternative featuring robust PDF editing and annotation tools.
microsoft office alternative - wps office

Frequently Asked Questions

Can I automate PDF page numbers from file names without using JavaScript?

Generally, no. Standard PDF editors can add sequential page numbers and static text, but automatically reading a file's name and converting it into a page number prefix dynamically requires JavaScript or a specialized third-party automation plugin.

How do I change the starting page number in a PDF?

In your PDF editor's Header and Footer settings, look for 'Page Number and Date Format' or 'Page Range Options'. Here you can specify a 'Start at' value so that your numbering begins at a specific digit rather than page 1.

Why are my custom page numbers overlapping with existing PDF content?

This happens when the margins for the Header or Footer are set too small. You can fix this by increasing the Top or Bottom margin values in the Header and Footer settings menu, pushing the page numbers further away from the document's main text.