How to Save a PDF Using Form Field Values with JavaScript
Question details
The user wants to automatically save a fillable PDF to a specific folder and generate its filename dynamically based on values entered into form fields using JavaScript.

- Product
- PDF Editor
- Device & OS
- not provided
- Scenario
- Automating document workflows by extracting form data (like names or dates) to generate a custom filename and save the document via a scripted form button.
- Observed behavior
- Setting up a trusted folder-level JavaScript function to execute a save action, and troubleshooting related issues such as "Missing Save Function" errors after a software upgrade.
Ensure you have administrative privileges on your computer, as you will need to access and place configuration files within the application's system-level installation folders.
Set Up a Folder-Level Trusted JavaScript Function
Create a trusted script file and place it in the application's JavaScript directory to safely bypass security restrictions and allow automatic saving.
For security reasons, standard document-level JavaScript cannot silently save files to a user's hard drive. To achieve this, you must create a folder-level script containing a 'trusted function'. This script acts as an elevated permission layer that the button in your PDF can call.
Open a plain text editor (like Notepad) and write a trusted function that uses the saveAs() method. The function should define parameters for the target directory and the custom filename.
Within your PDF button's JavaScript action, write code to retrieve values from your desired fields using syntax like this.getField("RequestedBy").value.
Concatenate the extracted field values (e.g., RequestedBy, NameofEvent, EventStartmdyy) with the target folder path to form the complete file path string.
Save your text file with a .js extension and place it into the user-level or system-level 'JavaScripts' folder of your PDF application.
Add a button to your PDF form. Set its action to 'Run a JavaScript' and call your newly created trusted function, passing the concatenated file path as a parameter.

Manage and Fill PDF Forms Easily with WPS Office
While setting up folder-level JavaScripts requires technical configuration, WPS Office provides an intuitive and accessible PDF editor to help you fill, extract, and manage PDF forms effortlessly.
- 1. Open the PDF form: Launch WPS Office and open your fillable PDF document.
- 2. Fill out the fields: Click on the interactive form fields and input your required data.
- 3. Save the document: Go to the Menu, select 'Save As', and choose your preferred folder and custom filename based on your entries.

Frequently Asked Questions
Why am I getting a "Missing Save Function" error after updating my PDF software?
Software updates often install into a new directory or overwrite existing configuration folders. Your trusted .js file was likely left in the old version's folder. You need to locate the new version's JavaScripts folder and move your script there.
Where is the JavaScripts folder located on my computer?
The system-level JavaScripts folder is typically located in the installation directory of your PDF software. For example, on Windows, it is often found under C:\Program Files (x86)\[Application Name]\JavaScripts.
Can I use JavaScript to email the PDF after saving it with the new name?
Yes, you can extend your trusted JavaScript function to include email methods (such as mailDoc). You can extract email addresses from form fields, attach the newly saved PDF, and generate an email draft automatically.




