How to Email a PDF Using Form Fields for Subject and Message
Question details
The user wants to configure an interactive button within a PDF form that triggers an email of the completed document, utilizing the data entered into specific form fields to populate the email's subject line and message body dynamically.

- Product
- Device & OS
- not provided
- Scenario
- Creating an interactive PDF document intended for user distribution, where submitting the form via email needs to be automated and cleanly formatted with the user's specific data.
- Observed behavior
- The user needs the precise JavaScript syntax and configuration steps to extract form data and execute an email command using the desktop PDF viewer's capabilities.
Ensure you are using a desktop PDF editor that supports JavaScript form actions, and that a default local email client (such as Microsoft Outlook or Apple Mail) is fully configured on your computer.
Configure a JavaScript Action on a PDF Form Button
Use the mailDoc method via a Mouse Up JavaScript action to extract specific field values and trigger your default email client with custom parameters.
Interactive PDF forms rely on JavaScript to pass data between the document and your computer's applications. By utilizing the mailDoc method, you can instruct the PDF viewer to open a new email draft, automatically attaching the current PDF and formatting the subject line based on user input.
Open your document in your desktop PDF editor, and navigate to the Form or Prepare Form toolset to view your existing form fields.
Insert a new 'Push Button' from the form controls toolbar, or right-click an existing button and select 'Properties' from the context menu.
In the Properties dialog box, go to the 'Actions' tab. Select 'Mouse Up' from the Select Trigger dropdown, and choose 'Run a JavaScript' from the Select Action dropdown.
Click the 'Add' button and paste the following script into the editor: var name = this.getField("CustomerName").valueAsString; var number = this.getField("InvoiceNumber").valueAsString; var subject = "Invoice " + number + " - " + name; var body = "Please find the completed form attached."; this.mailDoc({ bUI: true, cTo: "accounts@example.com", cSubject: subject, cMsg: body });
Replace "CustomerName" and "InvoiceNumber" with the exact names of your actual text fields. Save your PDF, exit form editing mode, and click the button to verify it launches your email client correctly.

Build and Manage Interactive PDF Forms with WPS Office
WPS Office provides robust and easy-to-use PDF editing tools that allow you to design professional, interactive forms. With advanced form controls, you can streamline data collection and workflow automation seamlessly.
- 1. Open WPS PDF: Launch WPS Office and open your existing PDF document or create a new one using the WPS PDF module.
- 2. Access Form Tools: Navigate to the 'Form' tab on the top ribbon to reveal the interactive form controls and editing tools.
- 3. Add Interactive Elements: Click on 'Push Button', 'Text Field', or other form elements, and drag them onto your document page.
- 4. Configure Properties: Right-click the inserted element, select 'Properties', and use the Actions tab to configure submission behaviors or scripts.

Frequently Asked Questions
Why doesn't the email button work when users open the PDF in Google Chrome?
Modern web browsers use their own built-in PDF viewers that intentionally restrict or disable advanced JavaScript functions like mailDoc for security reasons. Users must download the file and open it in a dedicated desktop PDF application to use the email button.
Can I configure the PDF to send the email silently without opening a draft?
While the mailDoc parameter 'bUI: false' is intended to suppress the user interface and send the email silently, most modern operating systems and email clients block this behavior to prevent unauthorized background emails. The user will typically still see a prompt or the email draft.
How do I find the exact field names to use in my JavaScript code?
You can find the exact field names by entering form editing mode in your PDF editor, right-clicking the specific text box or dropdown field, and selecting 'Properties'. The text listed under the 'Name' or 'General' tab is the identifier you must reference in your script.




