How to Automatically Display the PDF Filename in an Acrobat Header
Question details
The user wants to automatically display the current filename of a PDF document within the page header area.

- Product
- Adobe Acrobat
- Device & OS
- not provided
- Scenario
- Setting up a PDF document to dynamically show its own filename on the page for visual reference or printing.
- Observed behavior
- Acrobat does not have a built-in automated header feature for filenames, requiring a JavaScript workaround with form fields.
Ensure you are using the paid version of Adobe Acrobat (Standard or Pro), as the free Adobe Acrobat Reader does not support creating form fields or adding document-level JavaScript.
Use Document JavaScript to Populate a Text Field
Create a read-only text field in the header area and use a simple JavaScript code to automatically fill it with the document's filename.
This method requires creating a form field and adding a script that runs when the document opens. It ensures that even if the file is renamed later, the correct filename will be displayed.
Open your PDF in Adobe Acrobat and navigate to the 'Prepare Form' tool. Add a new text field in the header area of your document and name it exactly 'FileName'.
Right-click the newly created field, open its 'Properties', and under the 'General' tab, check the 'Read Only' box so users cannot manually edit the filename.
Go to the 'Tools' menu, select 'JavaScript', and then click on 'Document JavaScripts'.
Type a name for your script, click 'Add', and paste the following code outside of any function: `this.getField("FileName").value = this.documentFileName;`
Click 'OK' and save the document. Close and reopen the PDF to verify that the filename automatically appears in the header field.

Easily Manage PDF Headers and Footers with WPS Office
WPS Office provides a comprehensive PDF editing suite that allows you to easily add, edit, and manage headers, footers, and text fields in your PDF documents without needing complex JavaScript codes.
- 1. Open PDF: Open your PDF document in the WPS Office PDF editor.
- 2. Navigate to Insert: Click on the 'Insert' tab located on the top menu bar.
- 3. Add Header and Footer: Click on 'Header and Footer' to easily add custom text, such as the document filename, across your pages.
- 4. Save Changes: Apply the header settings and save your document to finalize the changes.

Frequently Asked Questions
Why does the document filename not show up when I use Adobe Acrobat Reader?
Adobe Acrobat Reader is a free viewer and does not support creating form fields or adding document-level JavaScript. You need the paid Adobe Acrobat version to set up the script and the text field.
Will the filename update automatically if the PDF is renamed on my computer?
Yes. Because the script uses the `this.documentFileName` property, it will fetch and display the current filename of the PDF every time the document is opened.
Can I use JavaScript to insert the current date in a PDF header?
Yes, similar to the filename, you can create a read-only text field and use a Document JavaScript like `this.getField("DateField").value = util.printd("mm/dd/yyyy", new Date());` to dynamically display the current date.




