PDF Editing Issues

How to Export Specific PDF Form Fields to an Email Body via JavaScript

Steve KSteve K Nov 24, 2026 868 views

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.

How to Export Specific PDF Form Fields to an Email Body via JavaScript
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.
Before you start

Ensure your PDF viewer or editor supports JavaScript execution and verify the exact names of the form fields you intend to extract data from.

Solution 1Recommended

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.

1
Open button properties

In your PDF form editing mode, right-click the interactive button you want to use, select 'Properties', and navigate to the 'Actions' tab.

2
Set the action trigger

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.

3
Write the extraction script

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;

4
Execute the mail function

Add the command to generate the email: app.mailMsg({bUI: true, cTo: 'recipient@example.com', cSubject: 'Form Submission', cMsg: emailBody}); and save your changes.

Add a Custom JavaScript Action to a Form Button
JavaScript Limitations: This JavaScript relies on the user's device having a properly configured default email client. It may not function as intended within web browsers or limited mobile PDF viewers.
Manage and Fill PDF Forms Effectively

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. 1. Open your PDF form: Launch WPS Office and open your interactive PDF document containing the form fields.
  2. 2. Fill interactive fields: Navigate to the 'Form' tab or simply click into the highlighted fields to input your specific data.
  3. 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.
Easily view and interact with PDF forms containing JavaScript.Seamlessly extract PDF form data or share files.Fully compatible with standard Adobe PDF form formats.Lightweight and intuitive interface for seamless document handling.
microsoft office alternative - wps office

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.