PDF Editing Issues

How to Automatically Display the PDF Filename in an Acrobat Header

Ayan MasoodAyan Masood Nov 5, 2026 869 views

Question details

The user wants to automatically display the current filename of a PDF document within the page header area.

How to Automatically Display the PDF Filename in an Acrobat Header
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.
Before you start

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.

Solution 1Recommended

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.

1
Create a Text Field

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'.

2
Set Field Properties

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.

3
Open Document JavaScripts

Go to the 'Tools' menu, select 'JavaScript', and then click on 'Document JavaScripts'.

4
Add the Script

Type a name for your script, click 'Add', and paste the following code outside of any function: `this.getField("FileName").value = this.documentFileName;`

5
Save and Test

Click 'OK' and save the document. Close and reopen the PDF to verify that the filename automatically appears in the header field.

Use Document JavaScript to Populate a Text Field
Application Title Bar: By default, the file name also appears in the application window's title bar, unless a specific document title is configured in the PDF's Initial View properties.
Powerful PDF Editor

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. 1. Open PDF: Open your PDF document in the WPS Office PDF editor.
  2. 2. Navigate to Insert: Click on the 'Insert' tab located on the top menu bar.
  3. 3. Add Header and Footer: Click on 'Header and Footer' to easily add custom text, such as the document filename, across your pages.
  4. 4. Save Changes: Apply the header settings and save your document to finalize the changes.
Easily insert page numbers, dates, and custom text into PDF headers.Fully compatible with Adobe Acrobat PDF formats and form fields.Intuitive interface for filling and creating PDF forms.Lightweight alternative to heavy PDF software.
microsoft office alternative - wps office

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.