Can Acrobat JavaScript Automatically Name a Saved PDF from a Form Field?
Question details
The user wants to use Acrobat JavaScript to extract an auto-generated invoice number from a form field and automatically place it into the Save dialog as the document's file name before emailing the form.

- Product
- Adobe Acrobat
- Device & OS
- not provided
- Scenario
- Submitting an interactive PDF invoice form via email where the invoice number needs to dictate the saved file name for organized record-keeping.
- Observed behavior
- Acrobat natively prevents document-level JavaScript from forcing a specific file name into the operating system's Save dialog due to strict security restrictions.
Before attempting to manipulate file saving processes, ensure you are using a desktop version of a PDF editor that supports JavaScript, as mobile readers and browser plugins typically disable form-level scripting.
Implement File Name Validation Before Form Submission
Since you cannot force the Save dialog to use a specific name, the best workaround is to use JavaScript to check the current document name against the required form field value before allowing the user to submit it.
Due to security protocols, standard document-level JavaScript cannot control the native Save As dialog. However, you can intercept the submit action to ensure the user has manually saved the file with the correct naming convention. If the file name doesn't match the required invoice number, the script will halt the submission and prompt the user to rename it.
Open your PDF form in Acrobat Pro. Navigate to the 'Tools' menu and select 'Prepare Form' to enter the form editing mode.
Add a new button to your form that users will click to submit the document by email. Double-click the button to open its Properties.
Go to the 'Actions' tab. Select 'Run a JavaScript' from the 'Select Action' dropdown, and click 'Add'. In the JavaScript editor, write a script that retrieves the target field value (e.g., var expectedName = this.getField('InvoiceNum').valueAsString + '.pdf';).
Add an if-statement comparing the 'expectedName' to 'this.documentFileName'. If they do not match, use 'app.alert' to instruct the user to go to File > Save As and rename the document, then exit the function. If they do match, execute the mail submission using 'this.mailDoc()'.

Manage and Edit PDF Forms Easily with WPS Office
Dealing with complex JavaScript limitations and expensive Adobe Acrobat subscriptions can be frustrating. WPS Office offers a free, lightweight, and comprehensive suite that includes a powerful PDF editor. Easily fill out interactive forms, edit text, and manage your documents seamlessly without worrying about intricate coding workarounds.
- 1. Download WPS Office: Visit the official WPS Office website and download the free desktop application for your operating system.
- 2. Open your PDF Form: Launch WPS Office and click on 'Open' to select your interactive PDF form.
- 3. Fill and Save: Use the WPS PDF tool to fill in your form fields, then go to Menu > Save As to easily name the file according to your requirements.

Frequently Asked Questions
Can I use 'this.saveAs()' to save a PDF without the Save dialog?
Yes, but 'this.saveAs()' is considered a privileged method. It can only be executed silently (without a dialog box) if the script is placed within a folder-level trusted function on the local computer. It cannot be run from a simple document-level button click by a standard user.
How do I check the current file name of my PDF using JavaScript?
You can retrieve the current name of the open PDF document by calling the 'this.documentFileName' property in your JavaScript code. This string can then be compared against form field values.
Why does Acrobat block scripts from controlling the native Save dialog?
Acrobat restricts document-level JavaScript from controlling native operating system dialogs, such as the Save As prompt, to prevent malicious documents from silently overwriting critical system files or saving harmful payloads to specific directories on a user's computer.
Is there a way to auto-email a PDF form with a specific subject line using JavaScript?
Yes. Unlike saving files, you can use the 'this.mailDoc()' function in Acrobat JavaScript to auto-populate the email subject and body. You can construct the subject line by extracting values from form fields and passing them as parameters to the mail function.




