How to Print PDF File Name in Header or Footer
Question details
The user needs to display and print the PDF document's filename automatically within the header or footer section for tracking and auditing purposes.

- Product
- Adobe Acrobat / PDF Editors
- Device & OS
- not provided
- Scenario
- Preparing documents for printing where maintaining a physical audit trail requires the exact digital filename to be visible on every printed page.
- Observed behavior
- Standard PDF print dialogs do not natively append the filename to the pages, requiring a custom script to inject the filename into the header or footer before the document is sent to the printer.
Ensure you are using a PDF editor that supports advanced document-level JavaScript actions, such as Adobe Acrobat Pro, before configuring automated print scripts.
Add Custom JavaScript to the Document's 'Will Print' Event
Use a document-level JavaScript triggered by the 'Will Print' event to dynamically fetch and display the file name before printing.
By binding a script to the 'Will Print' event, your PDF editor will automatically execute the code right before sending the document to the printer. This allows you to dynamically read the document's file name and insert it into a predefined header or footer form field, or generate a temporary watermark.
Launch your PDF editor, go to the 'Tools' menu, and open the 'JavaScript' or 'Document Actions' settings.
Choose 'Document Will Print' from the list of available event triggers and click 'Edit' or 'Add' to insert a new script.
Write a JavaScript code snippet using 'this.documentFileName' to retrieve the filename and set it as the value of your header/footer text field (e.g., this.getField('HeaderField').value = this.documentFileName;).
Save your PDF document to apply the script. Press Ctrl+P (or Cmd+P) to initiate a test print and verify that the filename successfully appears in the header or footer area.

Easily Add Headers and Footers to PDFs with WPS Office
If you prefer not to write complex JavaScript code, WPS PDF allows you to quickly insert custom text, including file names, page numbers, and dates, directly into the headers and footers of your document.
- 1. Open the PDF File: Launch WPS Office and open the PDF document you want to prepare for printing.
- 2. Access Header and Footer Tools: Navigate to the 'Insert' tab on the top ribbon and select 'Header and Footer'.
- 3. Add Custom Text: Click 'Add Header and Footer', then manually type the document's filename into the desired left, center, or right text box.
- 4. Customize Appearance: Adjust the font size, style, and margin settings to ensure the text fits perfectly, then click 'OK' to apply it to your pages.
- 5. Print the Document: Go to 'Menu' > 'Print' to print your PDF. The filename you added to the header or footer will automatically appear on the physical pages.

Frequently Asked Questions
Can I automatically print the file name on all my PDFs without editing each one individually?
Generally, custom JavaScript or header formatting must be added to each individual PDF. However, if you have Adobe Acrobat Pro or another advanced editor, you can use the 'Action Wizard' or batch processing tools to apply the 'Will Print' script to multiple files simultaneously.
Will using the 'Will Print' JavaScript permanently alter the text in my PDF?
It depends on how the script is written. If the script modifies a form field or adds a watermark during the 'Will Print' event, that change remains in the document. To prevent saving the filename permanently, you can add a corresponding script to the 'Did Print' event that clears the field or removes the watermark immediately after printing.
Is it possible to print the full directory path along with the file name?
Yes. If you are using JavaScript to generate the header, you can replace 'this.documentFileName' with the 'this.path' property. This will output the full folder location and the filename onto your printed document.




