How to Save a PDF Using a Text Field Value as the File Name
Question details
The user wants to automatically save a PDF file to a specific folder using the text entered into a specific form field as the file name.

- Product
- PDF Editor
- Device & OS
- not provided
- Scenario
- Automating the saving process of filled PDF forms to ensure consistent naming conventions based on user input.
- Observed behavior
- The user needs a script or method to extract the text field value and trigger a save action to a designated directory without manual intervention.
Ensure you have administrative access to the computers where this PDF will be used, as automated saving to local folders requires setting up a trusted JavaScript context.
Automate PDF Saving with Acrobat JavaScript
Use the saveAs method in a trusted context to automatically name and save the PDF based on a form field.
Because the saveAs method interacts directly with the local file system, it requires privileged access to prevent security risks. Standard document-level scripts cannot perform this action silently.
To achieve this, you must create a folder-level trusted script on each user's computer to execute the save action securely.
Create a JavaScript file (.js) on the local machine containing a trusted function that utilizes the app.trustedFunction and this.saveAs methods.
Place this .js file in the PDF application's privileged JavaScripts folder on every computer that will use the form.
Open your PDF form in your PDF editor, enter form editing mode, and add a new interactive Button to the document.
In the button's properties, add a 'Run a JavaScript' action for the 'Mouse Up' event. Write a script that retrieves the value of the text field using this.getField("YourTextFieldName").value.
Within the same button script, call the trusted function you created in step 1, passing the retrieved text field value to be used as the new file name.

Manage and Save PDF Forms Easily with WPS Office
WPS Office provides a comprehensive PDF editor that allows you to create, fill, and manage interactive PDF forms. While advanced automated local saving requires specific scripting environments, WPS PDF makes manual form filling, extracting data, and saving highly efficient.
- 1. Open the PDF form: Launch WPS Office and open your interactive PDF form using the WPS PDF tool.
- 2. Fill in the form fields: Click on the text fields to input your data, such as the person's name or ID.
- 3. Save the document: Go to 'Menu' and select 'Save As' to manually name the file using your entered data, ensuring cross-platform compatibility without complex scripting.

Frequently Asked Questions
Can I use the saveAs method without a trusted script?
No, for security reasons, modern PDF readers block document-level scripts from silently saving files to the local hard drive. A folder-level trusted script installed on the user's machine is mandatory.
How do I get the value of a text field in PDF JavaScript?
You can retrieve the value of a specific text field by using the script this.getField("YourTextFieldName").value within your PDF's JavaScript editor.
Does this automated saving work on mobile devices?
Generally, no. Folder-level trusted scripts and the saveAs method are designed for desktop environments (Windows/macOS) and are not supported in mobile PDF viewer apps due to strict OS sandboxing.




