How to Populate One PDF from Another Using Acrobat JavaScript
Question details
The user needs to automatically transfer form data from one PDF document to another using JavaScript.

- Product
- Adobe Acrobat
- Device & OS
- not provided
- Scenario
- Transferring form data between documents when a user selects a checkbox or opens a second file.
- Observed behavior
- Requires correct configuration of field names, document paths, and utilization of the openDoc API method while managing PDF security restrictions.
Ensure both PDF documents are saved in the same local directory or a trusted folder, as cross-document JavaScript execution is often restricted by default security settings.
Use the openDoc Method to Transfer Form Data
The most reliable way to pull data from another PDF is by using the JavaScript API's app.openDoc() method to access the source document's fields and extract their values.
Cross-document interactions in PDFs require both documents to be accessible to the script. The app.openDoc() method allows the current destination document to open a secondary source document in the background and read its field values.
Depending on your software's security settings, this method may require you to configure folder-level scripts or create a trusted function to bypass cross-file restrictions.
Open your destination PDF in your PDF editor, navigate to the Tools menu, and select 'Prepare Form' or 'Form Editing' mode.
Right-click the trigger element, such as a checkbox or button, and select 'Properties' from the context menu.
Go to the 'Actions' tab, choose 'Run a JavaScript' from the Select Action dropdown, and click the 'Add' button.
Input the JavaScript code using app.openDoc('source.pdf') to open the source file. Map the data by adding: this.getField('TargetField').value = sourceDoc.getField('SourceField').value;
Click 'OK' to save the script, exit form editing mode, and test the trigger to ensure the data populates correctly.

Easily Manage and Edit PDF Forms with WPS Office
While advanced cross-document JavaScript requires specialized scripting and security bypasses, WPS Office provides an intuitive, comprehensive PDF editor that allows you to easily create, edit, fill, and manage PDF forms without complex code.
- 1. Open your PDF: Download and launch WPS Office, then open your PDF document containing the forms.
- 2. Access the Form tab: Navigate to the 'Form' tab on the top ribbon to access the interactive form field tools.
- 3. Edit or fill fields: Click on 'Text Field', 'Checkbox', or other elements to manually insert or edit form data without needing external scripts.
- 4. Merge documents safely: If you need data from multiple files, use the 'Merge PDF' tool to combine multiple forms into a single file, completely avoiding cross-document scripting issues.

Frequently Asked Questions
Why does the app.openDoc() method fail to open the second PDF?
This usually occurs due to enhanced security settings in modern PDF readers. Both files must be located in a 'Privileged Location' or 'Trusted Folder', or the script must be executed via a trusted folder-level function.
Can I transfer PDF form data without using JavaScript?
Yes, you can manually export form data as an FDF or XML file from the source PDF via the Form settings, and then import that data file into the destination PDF using the 'Import Data' feature.
How do I trigger the JavaScript as soon as the PDF opens?
You can assign the JavaScript action to the 'Page Open' event under the document's Page Properties, or set it up as a Document-Level script that executes upon file initialization.




