How to Automatically Rename a PDF Form Before Email Submission
Question details
The user wants to use specific form field values, such as dealer name or machine serial number, to automatically generate a custom filename or email subject when submitting a completed PDF form.

- Product
- PDF Editors
- Device & OS
- not provided
- Scenario
- Preparing a fillable PDF form for distribution where completed submissions need to be automatically organized by custom filenames derived from user input.
- Observed behavior
- Currently, PDF forms retain their original filenames upon submission unless manually saved or altered via advanced document-level scripting.
Ensure you have an advanced PDF editor capable of executing document-level JavaScript, and be aware that local security restrictions on the recipient's computer may block customized save scripts.
Use JavaScript to Generate a Custom Filename
Apply document-level JavaScript to pull form field data and use it to format the filename and email subject upon submission.
Standard PDF submission buttons cannot dynamically change a filename. However, you can achieve this using a trusted JavaScript function that pulls data from specific text fields.
Note that local security settings on the user's computer must allow scripts to execute, and silent saving often requires application-level trusted functions.
Open your PDF form in edit mode and identify the exact properties of the fields you want to use (e.g., 'DealerName', 'SerialNumber').
Navigate to the JavaScript or Action tools in your PDF editor and create a new document-level script.
Write a script that combines the field values into a variable. For example: var newName = this.getField('DealerName').value + '_' + this.getField('SerialNumber').value;
Use the app.execMenuItem('SaveAs') API or specific mail submission APIs utilizing your newName variable to trigger the renaming and email generation.
Right-click your custom 'Submit' button, go to Properties, select 'Actions', set the Trigger to 'Mouse Up', and choose 'Run a JavaScript' to bind your script.
Provide Manual Save Instructions for Users
If JavaScript is blocked by strict IT security policies, guide users to manually rename the file using a specific convention before emailing.
Edit and Manage PDF Forms Easily with WPS Office
WPS Office provides a comprehensive PDF editor that allows you to create interactive forms, manage text fields, and streamline document submission workflows without extensive technical knowledge.
- 1. Launch WPS PDF: Open WPS Office and navigate to the 'PDF' tab to launch the dedicated WPS PDF Editor.
- 2. Open Your Form: Open your existing PDF document or create a new blank PDF to start building your form.
- 3. Add Interactive Fields: Go to the 'Form' tab to insert text fields, dropdowns, and buttons. Double-click any field to customize its name and properties.
- 4. Save and Distribute: Save your completed interactive PDF form and share it with your clients or team members for easy data collection.

Frequently Asked Questions
Can I automatically rename a PDF without using JavaScript?
No, standard built-in PDF features do not support dynamic file renaming based on user input. Advanced scripting or manual renaming by the user is required to achieve a customized filename.
Why does my JavaScript 'SaveAs' function fail on other computers?
Modern PDF viewers restrict scripts from silently saving files to prevent malicious activity. A trusted script must be installed locally in the application's configuration folder, or users must manually approve the save location.
Does the submit button automatically attach the PDF to an email?
Yes, a PDF submit button can be configured with a 'mailto:' action to open the user's default email client and attach the filled form. However, the attachment's filename will be the current file's name unless it was altered beforehand.




