How to Automatically Insert a PDF File Name in Acrobat Pro
Question details
The user wants to automatically display a PDF's file name inside the document pages using Adobe Acrobat Pro.

- Product
- Adobe Acrobat Pro
- Device & OS
- not provided
- Scenario
- Adding dynamic document information, such as the current file name, into the visible pages of a PDF file.
- Observed behavior
- The user needs to utilize Acrobat JavaScript and form text fields to automatically fetch and display the file name.
Ensure you have Adobe Acrobat Pro installed, as standard PDF readers do not have the necessary permissions to create form fields or write document-level JavaScript.
Auto-Insert File Name using Acrobat JavaScript
Create a custom text field and use a document-level JavaScript to automatically populate it with the current PDF file name.
This method involves creating a placeholder text field in your PDF and writing a short JavaScript snippet that tells Acrobat to read the file's name and display it in that field automatically.
Open your document in Acrobat Pro and go to the 'Prepare Form' tool. Add a new Text Field exactly where you want the file name to appear.
Give the text field a unique and identifiable name, such as 'FileNameField'. Right-click the field to access its Properties, where you can make it 'Read Only' and adjust the font size to match your document.
Navigate to 'Tools' > 'JavaScript' > 'Document JavaScripts'. Type a name for your new script and click 'Add'.
In the editor, delete the default code and enter the following script: this.getField('FileNameField').value = this.documentFileName; then click 'OK'.
Save your PDF document, close it, and reopen it. The text field should now automatically display the file name. Test this on a copy of your document to verify.

Easily Edit and Manage PDFs with WPS Office
While advanced JavaScript requires Adobe Acrobat Pro, WPS Office provides a highly intuitive PDF editor that lets you quickly add text, headers, and footers to your documents without writing complex code.
- 1. Open your PDF in WPS Office: Download and launch WPS Office, then open your target PDF document.
- 2. Navigate to Header and Footer: Go to the 'Insert' or 'Edit' tab and select the 'Header and Footer' option.
- 3. Insert the File Name: Choose 'Add Header and Footer', type your file name into the desired section, and apply it uniformly across all pages.
- 4. Save the Document: Click 'Save' or press Ctrl+S to finalize your changes instantly.

Frequently Asked Questions
Why isn't the JavaScript updating the file name when I rename the PDF?
Document-level JavaScripts usually trigger when the document is initially opened or printed. If you rename the file while it is currently open, the script will not refresh automatically. You must close and reopen the PDF to see the updated name.
Can I use this JavaScript method in Adobe Acrobat Reader?
No, creating form fields and embedding document-level JavaScript requires Adobe Acrobat Pro or Standard. Users with the free Acrobat Reader can only view and execute the script if a Pro user has already embedded it into the document.
Is there a way to add the full file path instead of just the file name?
Yes. In your JavaScript snippet, you can replace 'this.documentFileName' with the 'this.path' property. This will retrieve and display the full directory path of the PDF file inside your text field.




