How to Create a Save As Button with an Automatic PDF File Name
Question details
The user wants to add a Save As button to an interactive PDF form that automatically saves the file to a specific folder with a dynamically generated name based on form fields.

- Product
- Device & OS
- not provided
- Scenario
- Creating interactive PDF forms to collect user data and streamline the saving process.
- Observed behavior
- The user needs a method to automate the Save As workflow, using form field values (such as Name and Date) to determine the output file name.
Before adding JavaScript to your PDF form, ensure your PDF editing software supports form field scripting and that you have noted the exact names of the text fields you plan to use for the file name.
Use JavaScript to Create a Dynamic Save As Button
Add a custom JavaScript action to a PDF button that combines form field values to generate the file name and executes the save action.
You can use PDF JavaScript to fetch values from specific form fields and construct a dynamic file path. Note that strict security restrictions in most modern PDF viewers may require user confirmation before saving to a local folder.
Open your PDF form in editing mode, navigate to the forms toolbar, and insert a new Button field at the desired location in the document.
Right-click the newly created button and select Properties. Give the button an intuitive label like 'Save Document'.
Go to the Actions tab in the Properties window. Select 'Mouse Up' as the trigger, choose 'Run a JavaScript' from the action dropdown menu, and click the Add button.
In the JavaScript editor, define your variables by fetching field values (e.g., var fileName = this.getField('Name').value + '_' + this.getField('Date').value;). Then, use the saveAs method: this.saveAs({cPath: "/c/Folder/" + fileName + ".pdf"});
Save your PDF, exit form editing mode, fill in the target fields, and click the button to verify the automated naming and saving process.

Edit and Fill PDF Forms Easily with WPS Office
WPS Office provides a comprehensive PDF toolkit that allows you to view, fill, and manage interactive PDF forms effortlessly without needing expensive software.
- 1. Download and Install: Download WPS Office and open your interactive PDF document using the WPS PDF tool.
- 2. Fill the Form: Click on the interactive text fields to enter your name, date, and other required information directly.
- 3. Save the Document: Click 'Menu' and select 'Save As' to easily save the completed form to your preferred directory with your chosen file name.

Frequently Asked Questions
Why does the saveAs JavaScript method fail in some PDF readers?
Most modern PDF readers have strict security sandboxes that prevent scripts from silently saving files to a user's local drive without explicit permission. Users may need to adjust their security preferences or use application-level 'Trusted Functions' to allow silent saving.
Can I automatically attach the renamed PDF to an email instead of saving it?
Yes, you can use the 'this.mailDoc()' JavaScript method in conjunction with form fields to automatically draft an email and attach the filled PDF form. This will prompt the user's default desktop email client to open.
Do I need advanced coding experience to create dynamic PDF buttons?
Basic JavaScript knowledge is required to write scripts that fetch field values and trigger document actions. However, many standard PDF scripts can be easily copied from tutorials and adapted simply by replacing the field names to match your form.




