How to Display and Automatically Update a PDF File Path
Question details
The user wants to insert a dynamic text field into a PDF that automatically displays and updates the document's current file path when it is opened or saved to a new location.

- Product
- Adobe Acrobat
- Device & OS
- not provided
- Scenario
- Creating a dynamic PDF document where the specific file path needs to be visible and self-updating for document management or distribution purposes.
- Observed behavior
- The user needs a method to dynamically fetch and display the file path upon opening or saving the document, as static text does not update when the file is moved.
Ensure your PDF editor supports advanced form fields and JavaScript execution, as basic viewers (like web browsers or mobile apps) typically do not support document-level scripts.
Implement Document-Level JavaScript to Update File Path
Use a read-only text field and a custom JavaScript action to dynamically display the file's current location whenever it is opened or saved.
This method uses a simple script to pull the document's path. Keep in mind that JavaScript features are fully supported in robust desktop PDF editors like Adobe Acrobat but may not work in browser-based or mobile PDF viewers.
Open your PDF document and create a new form text field. Name this text field exactly "FilePath" and set its properties to "Read-Only" so users cannot manually edit the text.
Navigate to Tools > JavaScript > Document JavaScripts. Add a new script and name it "load". Delete any automatically generated code in the script window and replace it with: this.getField("FilePath").value = this.path;
If you want the field to update immediately when the file is saved to a new location, go to Tools > JavaScript > Set Document Actions. Select "Did Save" and paste the exact same code there.
Save your PDF file, close it entirely, and reopen it. The "FilePath" text field should now automatically display the correct current file path on your system.

Insert Text and Manage PDFs Using WPS Office
WPS Office includes a powerful PDF editor that lets you easily manage document properties, insert text fields, and edit content without relying on expensive software.
- 1. Open PDF in WPS: Download and launch WPS Office, then select your PDF file to open it in the built-in PDF Editor.
- 2. Navigate to Insert: Click on the "Insert" or "Form" tab on the top ribbon to access the text box and interactive field tools.
- 3. Add Your Details: Place a text box anywhere on the document to manually note your document's file path, version, or other essential tracking information.
- 4. Save the Document: Click the "Save" icon or use Ctrl+S to securely save your customized PDF file to your desired local or cloud location.

Frequently Asked Questions
Why doesn't the file path update when I open the PDF in Google Chrome?
Most web browsers, including Google Chrome, Microsoft Edge, and Firefox, use basic built-in PDF viewers that do not support document-level JavaScript. The script required to update the file path will only execute in fully-featured desktop PDF applications.
Can I display the file path dynamically without using JavaScript?
No, standard PDF features do not include a dynamic, self-updating file path variable by default. You must either manually type the path into a standard text box or use JavaScript to pull the data automatically.
Will this JavaScript work on PDF viewers for mobile devices?
Typically, no. Built-in PDF viewers on iOS and Android phones and tablets usually lack support for advanced PDF JavaScript. If opened on mobile, the file path field may remain blank or display the last saved static path.
How do I ensure the file path updates immediately when I use 'Save As'?
You need to add the same JavaScript code to the 'Did Save' document action. Navigate to Tools > JavaScript > Set Document Actions, select 'Did Save', and paste your custom code there so it triggers immediately after a save operation.




