How to Create a PDF Button That Opens an Embedded Attachment
Question details
The user wants to configure an interactive button within a PDF document that, when clicked, launches a specific file that is embedded as an attachment in the same PDF.

- Product
- Device & OS
- not provided
- Scenario
- Creating an interactive PDF form or presentation where supplemental files need to be easily accessible to readers via a single click of a button.
- Observed behavior
- The user needs the specific Acrobat JavaScript method and configuration steps to successfully link a form button to an attached file.
Ensure that the supplementary file you wish to open is already embedded within your PDF document's attachment panel, and note its exact file name including the extension.
Use Acrobat JavaScript to Link a Button to a PDF Attachment
By assigning a specific JavaScript command to a button's properties, you can extract and launch an embedded file instantly when the button is clicked.
PDF editing software allows you to use JavaScript to extend the functionality of interactive elements. To open an embedded attachment, you must use the 'exportDataObject' method, which extracts the attached file and prompts the operating system to open it with its default application.
Open the Attachments panel in your PDF editor, add the file you want to link (e.g., 'document.docx'), and copy the exact filename.
Navigate to the 'Form' or 'Prepare Form' tools, select the 'Button' tool, and drag a rectangle on the document page where you want the button to appear.
Right-click the newly created button and select 'Properties' from the context menu to open the Button Properties dialog box.
Go to the 'Actions' tab. Select 'Mouse Up' as the trigger, choose 'Run a JavaScript' from the Select Action dropdown menu, and click the 'Add' button.
In the JavaScript Editor window, paste the following code: this.exportDataObject({cName: "file.txt", nLaunch: 2}); replacing "file.txt" with the exact name of your embedded attachment. Click OK and close the properties panel.

Create Interactive PDFs Easily with WPS Office
WPS Office provides a comprehensive PDF toolkit that allows you to easily manage attachments, edit documents, and insert interactive form controls like buttons with custom actions.
- 1. Open your Document: Launch WPS Office and open your PDF file using the built-in PDF editor.
- 2. Embed your Attachment: Click the 'Attachment' icon in the navigation pane on the left, then click the Add button to embed your file into the PDF.
- 3. Add a Form Button: Navigate to the 'Form' tab, select the 'Push Button' tool, and draw your button on the page.
- 4. Configure Button Action: Double-click the button to open its properties, go to the Actions tab, and set up your link or JavaScript action to launch the attachment.

Frequently Asked Questions
Why isn't my PDF button opening the attachment?
This issue typically occurs if the filename specified in the JavaScript code does not perfectly match the embedded attachment's name (including its file extension). Additionally, the PDF viewer's security settings may be actively blocking JavaScript execution.
What does 'nLaunch: 2' mean in the JavaScript code?
The 'nLaunch: 2' parameter instructs the PDF viewer to save the embedded file to a temporary location and then ask the device's operating system to open it using the default application associated with that specific file type.
Can I use this JavaScript to open an external file on my computer?
No, the 'this.exportDataObject' method is specifically designed to target and extract data objects (attachments) embedded directly inside the PDF file itself. To link to an external file path, you would use an 'Open a file' action instead.




