Change a PDF Email Subject and File Name with Acrobat JavaScript
Question details
Add the value of a LAST NAME form field to a submitted PDF's email subject and file name.

- Product
- Adobe Acrobat
- Device & OS
- not provided
- Scenario
- A fillable PDF has a Send button that should email the completed form with the user's last name in the subject and attachment name.
- Observed behavior
- The desired result is an email subject and PDF file name that include the value entered in the LAST NAME field.
Open the fillable PDF in Acrobat and confirm that the field is named exactly LAST NAME. You will also need access to the Send button's properties and an email application for testing.
Add the last name to the email subject with Acrobat JavaScript
Use a button action to create an email subject from the form field value.
The script sets the email subject; it does not automatically rename the PDF attachment. Automatic renaming may require a script installed on each user's computer.
In Acrobat, open the PDF, select Prepare a Form, then double-click the Send button to open its properties.
On the Actions tab, set the trigger to Mouse Up, choose Run a JavaScript, and select Add.
In the JavaScript editor, enter: var lastName = this.getField("LAST NAME").valueAsString; this.mailDoc({cTo:"me@server.com", cSubject:"Submitted by: " + lastName}); Replace me@server.com with the recipient's email address.
Close the editor and button properties, save the PDF, enter a value in LAST NAME, and click Send. Check the resulting email subject before sending.

Save the completed PDF with the desired file name
Use this manual approach when you cannot install a local renaming script on each user's computer.
Save and email a named PDF with WPS Office
Use WPS PDF to complete the form and save a copy with the last name in its file name. Then attach it to an email and enter the subject manually; this workflow does not automate the Acrobat button script.
- 1. Open the form: Open WPS Office, select Open, and choose the fillable PDF.
- 2. Complete the field: Click the LAST NAME field and enter the user's last name, then complete the remaining form fields.
- 3. Save a named copy: Choose Save As and enter a PDF file name that includes the last name.
- 4. Create the email: In your email application, create a message, attach the saved PDF, and type a subject such as Submitted by: followed by the last name.

Frequently Asked Questions
Does the Acrobat script rename the PDF attachment?
No. The mailDoc script sets the email subject. Automatic attachment renaming may require a local script on each user's computer; otherwise, save the PDF under the desired name before sending.
Why is the last name missing from the email subject?
Check that the user entered a value and that the field's name in Prepare a Form is exactly LAST NAME. The name in getField must match the form field name.
Where do I add the JavaScript to the Send button?
In Acrobat, open Prepare a Form, double-click the button, and use Actions > Mouse Up > Run a JavaScript > Add.
Can I send the PDF without using the button script?
Yes. Save the completed PDF with File > Save As, attach that saved copy in your email application, and type the subject manually.




