How to Open an Attached PDF from a Drop-Down Field Using JavaScript in Acrobat
Question details
The user needs to use a JavaScript calculation script to automatically open an embedded PDF file when a specific option is selected from a drop-down field.

- Product
- Adobe Acrobat
- Device & OS
- not provided
- Scenario
- Triggering the opening of an attached or embedded PDF file upon selecting a specific value from a drop-down menu within a PDF form.
- Observed behavior
- The JavaScript code fails to execute and open the attachment because property names, specifically 'nLaunch', are case-sensitive and were incorrectly capitalized.
Ensure that your primary PDF already contains the embedded file attachment and that your environment allows JavaScript execution for interactive PDF forms.
Correct the Capitalization of the nLaunch Property
Fix the syntax of your JavaScript code by using the correctly capitalized property name 'nLaunch' to ensure the embedded file opens properly.
Acrobat JavaScript is strictly case-sensitive. When using the exportDataObject method to open an embedded attachment, the property parameter must be capitalized exactly as required by the API. Using 'nlaunch' instead of 'nLaunch' will cause the script to fail quietly.
Open your PDF form in Adobe Acrobat, right-click the target drop-down field, and select 'Properties'.
Navigate to the 'Calculate' tab, select 'Custom calculation script', and click 'Edit'.
Input the script using the correct capitalization: if (event.value == "Your Target Value") this.exportDataObject({cName: "your-attachment.pdf", nLaunch: 2});
Ensure that the value assigned to 'cName' exactly matches the file name of the embedded PDF, including the .pdf extension.
Click 'OK' to save the script, exit form editing mode, and select the value from the drop-down to test if the attached PDF opens successfully.

Manage PDF Forms and Attachments with WPS Office
WPS Office provides a comprehensive PDF editor that allows you to effortlessly view, manage attachments, and interact with PDF forms without needing complex JavaScript debugging.
- 1. Download and Install: Download WPS Office Free and install it on your device.
- 2. Open Your PDF: Launch WPS PDF and open the document containing the form fields or attachments.
- 3. Access Attachments Directly: Click on the 'Attachment' pane on the left sidebar to instantly view and open any embedded files without relying on scripts.
- 4. Interact with Forms: Navigate to the 'Form' tab to seamlessly fill out drop-down fields and other interactive elements.

Frequently Asked Questions
Why isn't my Acrobat JavaScript opening the attached PDF?
The most common reason is incorrect capitalization of JavaScript properties. Ensure you are using 'nLaunch' instead of 'nlaunch', and verify that the attachment name defined in 'cName' matches the actual embedded file perfectly.
What does 'nLaunch: 2' do in the exportDataObject method?
In Acrobat JavaScript, setting 'nLaunch: 2' instructs the application to save the extracted embedded file to a temporary location and immediately open it using the default system application associated with that file type.
Can I open an embedded file from a button click instead of a drop-down?
Yes. You can attach the same exportDataObject JavaScript code to the 'Run a JavaScript' action under the 'Mouse Up' trigger within a button's properties.




