PDF Editing Issues

How to Create a PDF Button That Opens an Embedded Attachment

Amos GikundaAmos Gikunda Nov 3, 2026 869 views

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.

How to Create a PDF Button That Opens an Attachment
Product
PDF
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.
Before you start

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.

Solution 1Recommended

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.

1
Insert the Attachment

Open the Attachments panel in your PDF editor, add the file you want to link (e.g., 'document.docx'), and copy the exact filename.

2
Add a Button Field

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.

3
Access Button Properties

Right-click the newly created button and select 'Properties' from the context menu to open the Button Properties dialog box.

4
Set the JavaScript Action

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.

5
Enter the JavaScript Code

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.

Use Acrobat JavaScript to Link a Button to a PDF Attachment
PDF Security Prompt: Depending on the viewer's PDF security settings, clicking the button may trigger a security prompt asking for permission to launch the file. The user must allow this action for the file to open.
Powerful PDF Editor

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. 1. Open your Document: Launch WPS Office and open your PDF file using the built-in PDF editor.
  2. 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. 3. Add a Form Button: Navigate to the 'Form' tab, select the 'Push Button' tool, and draw your button on the page.
  4. 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.
Easily insert, view, and manage embedded PDF attachments.Fully compatible with standard PDF interactive forms and Adobe Acrobat format features.Lightweight, fast, and completely free to download.Seamless document editing and reading experience across Windows, Mac, and mobile devices.
microsoft office alternative - wps office

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.