PDF Editing Issues

Change a PDF Email Subject and File Name with Acrobat JavaScript

Aamir Naveed AkramAamir Naveed Akram Nov 19, 2026 868 views

Question details

Add the value of a LAST NAME form field to a submitted PDF's email subject and file name.

Change a PDF Email Subject and File Name with Acrobat JavaScript
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.
Before you start

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.

Solution 1Recommended

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.

1
Open the button properties

In Acrobat, open the PDF, select Prepare a Form, then double-click the Send button to open its properties.

2
Add a JavaScript action

On the Actions tab, set the trigger to Mouse Up, choose Run a JavaScript, and select Add.

3
Enter the script

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.

4
Save and test

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.

Add the last name to the email subject with Acrobat JavaScript
Attachment naming: If a local script cannot be installed for every user, ask users to save the completed PDF under the desired name before sending it.
A manual PDF workflow

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. 1. Open the form: Open WPS Office, select Open, and choose the fillable PDF.
  2. 2. Complete the field: Click the LAST NAME field and enter the user's last name, then complete the remaining form fields.
  3. 3. Save a named copy: Choose Save As and enter a PDF file name that includes the last name.
  4. 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.
Save a completed PDF with a descriptive file nameEnter the last name in the email subject manuallyOpen and edit Microsoft Word, Excel, and PowerPoint formatsUse a familiar interface for PDF and office documents
microsoft office alternative - wps office

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.