How to Export Specific PDF Form Fields to an Email Body via JavaScript
Question details
The user needs a way to extract data from specific PDF form fields and automatically construct a new email containing those field values as plain text when a button is clicked.

- Product
- PDF Editor
- Device & OS
- not provided
- Scenario
- Designing an interactive PDF form where users can submit specific field data via an automatically generated email.
- Observed behavior
- The goal is to trigger a script upon clicking a PDF button that reads the specified form fields and opens the user's default email client with a pre-populated message body.
Ensure your PDF viewer or editor supports JavaScript execution and verify the exact names of the form fields you intend to extract data from.
Add a Custom JavaScript Action to a Form Button
Use a built-in JavaScript action in your PDF editor's form properties to retrieve field values and trigger an email.
By utilizing the 'app.mailMsg' function in JavaScript, you can construct an email dynamically from user inputs. This requires access to a professional PDF editor capable of modifying interactive form properties.
In your PDF form editing mode, right-click the interactive button you want to use, select 'Properties', and navigate to the 'Actions' tab.
Select 'Mouse Up' from the 'Select Trigger' dropdown menu, and choose 'Run a JavaScript' from the 'Select Action' dropdown menu. Click 'Add' to open the JavaScript editor.
Enter the code to retrieve your field values. For example: var fieldA = this.getField('FieldNameA').value; var fieldB = this.getField('FieldNameB').value; var emailBody = 'Field A: ' + fieldA + '\nField B: ' + fieldB;
Add the command to generate the email: app.mailMsg({bUI: true, cTo: 'recipient@example.com', cSubject: 'Form Submission', cMsg: emailBody}); and save your changes.

Manage and Fill PDF Forms with WPS PDF
WPS Office offers a comprehensive PDF editor that lets you view, fill, and manage interactive PDF forms effortlessly. Seamlessly interact with documents without needing expensive software.
- 1. Open your PDF form: Launch WPS Office and open your interactive PDF document containing the form fields.
- 2. Fill interactive fields: Navigate to the 'Form' tab or simply click into the highlighted fields to input your specific data.
- 3. Share or export data: Use WPS PDF's built-in sharing features to email the document directly or save the completed form to your device.

Frequently Asked Questions
Why isn't the JavaScript button opening my email client?
This typically happens if your default email client is not configured correctly on your operating system, or if your PDF viewer restricts JavaScript execution for security reasons.
Can I attach the PDF file itself instead of just the text?
Yes, you can use the 'app.mailDoc()' JavaScript method instead of 'app.mailMsg()' if you want to attach the entire active PDF document to the email rather than just extracting text to the body.
How do I find the exact names of my form fields?
In your PDF editor's form preparation mode, right-click the specific text box or element and check its 'Properties'. The 'Name' field listed under the General tab is the exact string you must use in your JavaScript code.
Will this JavaScript work in all PDF viewers?
No. Advanced JavaScript functions like 'app.mailMsg' are fully supported in robust desktop applications like Adobe Acrobat Pro and WPS Office, but they often fail to execute in browser-based PDF viewers or basic mobile apps.




