Merge PDF Form Fields with Adobe Acrobat JavaScript
Question details
Combine name and address fields from a source PDF form into fields in a service agreement or renewal form.

- Product
- Adobe Acrobat
- Device & OS
- not provided
- Scenario
- A user wants to transfer and concatenate values from one PDF form into another using Acrobat JavaScript.
- Observed behavior
- The destination form should contain combined text from the corresponding source fields.
Open both forms in Acrobat and check their exact field names in Prepare a Form. Confirm that JavaScript is enabled and that you have permission to edit the forms.
Use an Acrobat button to combine source PDF fields
Use this method when you can edit both forms and want a button to populate the destination address field.
The source document must be disclosed before another document can access its fields. Use valueAsString to combine field values as text.
The example joins address fields with commas. Empty fields will still produce separators, so adjust the script if you want to omit them.
In the source PDF, open All tools > Use JavaScript > Document JavaScripts, add a script containing this.disclosed = true;, and save the PDF.
Open Prepare a Form in each PDF and verify the source names Address_1, Address_2, Suburb, State, and Postcode, as well as the destination name Address. Correct any spelling differences in the script.
In the destination PDF, open Prepare a Form and add or select a button. In its Properties > Actions tab, select Mouse Up, choose Run a JavaScript, and click Add.
Enter the following script, replacing the filename or field names as needed: var cData = app.openDoc("EPM Service Request V4.pdf"); this.getField("Address").value = cData.getField("Address_1").valueAsString + ", " + cData.getField("Address_2").valueAsString + ", " + cData.getField("Suburb").valueAsString + ", " + cData.getField("State").valueAsString + ", " + cData.getField("Postcode").valueAsString;
Save the destination PDF, exit form editing, and click the button. Check that the Address field contains the expected source values. For names, add a similar assignment using the exact source and destination name field names.

Work with PDFs and Office documents in WPS Office
WPS Office is a free, lightweight alternative with a familiar interface for working with PDFs and Office documents. Its format compatibility makes it easier to move existing files into your workflow. Acrobat-specific JavaScript and security settings must still be handled in Acrobat.

Frequently Asked Questions
Why must the source PDF be disclosed?
Setting this.disclosed = true; in a document-level script allows other documents to access the source document's properties and fields, subject to Acrobat's security restrictions.
How do I find the exact PDF field names?
Open each PDF in Acrobat and choose Prepare a Form. Select the fields and inspect their properties, then use the exact names in the JavaScript.
Why does the button fail to open the source PDF?
Check the filename and path supplied to app.openDoc, and confirm that the source document is accessible. Acrobat security restrictions can also block the call; a trusted function may be required in an authorized environment.
Can I combine name fields as well as address fields?
Yes. In the button's Run a JavaScript action, add another assignment that joins the source name fields with valueAsString and writes the result to the destination name field. Use the exact field names from both forms.




