logo
search
PDF Editing Issues

How to Automatically Insert a PDF File Name in Acrobat Pro

Algirdas JasaitisAlgirdas Jasaitis Oct 23, 2026 869 views

Question details

The user wants to automatically display a PDF's file name inside the document pages using Adobe Acrobat Pro.

How to Automatically Insert a PDF File Name in 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.
Before you start

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.

Solution 1Recommended

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.

1
Create a Text Field

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.

2
Name and Customize the Field

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.

3
Access Document JavaScripts

Navigate to 'Tools' > 'JavaScript' > 'Document JavaScripts'. Type a name for your new script and click 'Add'.

4
Enter the JavaScript Code

In the editor, delete the default code and enter the following script: this.getField('FileNameField').value = this.documentFileName; then click 'OK'.

5
Save and Test

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.

Auto-Insert File Name using Acrobat JavaScript
Security Settings Notice: JavaScript access can vary based on your Acrobat security settings. Always test the script on a duplicate copy of your PDF first to ensure it functions as intended.

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. 1. Open your PDF in WPS Office: Download and launch WPS Office, then open your target PDF document.
  2. 2. Navigate to Header and Footer: Go to the 'Insert' or 'Edit' tab and select the 'Header and Footer' option.
  3. 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. 4. Save the Document: Click 'Save' or press Ctrl+S to finalize your changes instantly.
Easily add headers, footers, and page numbers to PDFsEdit PDF text, images, and shapes smoothlyHighly compatible with standard Adobe Acrobat PDF formatsLightweight, fast, and features a user-friendly interface
microsoft office alternative - wps office

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.