Create an Acrobat Button to Attach and Open a File
Question details
Create an Acrobat button workflow that attaches a file to a PDF and opens the same attachment later.

- Product
- Adobe Acrobat
- Device & OS
- not provided
- Scenario
- A PDF form needs buttons that add a file and later locate and open that attachment.
- Observed behavior
- The workflow depends on whether the file is embedded as a data object or added as a file attachment comment.
Open the PDF in Acrobat and check whether the existing file is a regular attachment or a file attachment comment. You will need access to Prepare a Form and JavaScript actions to create the buttons.
Use Acrobat JavaScript buttons with a data-object attachment
Use a named data object when the PDF needs to attach a file and open that same attachment later.
The attachment name in the import and open actions must match. File attachment comments do not support this data-object workflow.
In Acrobat, open Prepare a Form, add a button, and open its Properties. On the Actions tab, select Mouse Up and Run a JavaScript, then click Add.
Enter this script in the JavaScript editor: this.importDataObject({cName: "MyAttachment"}); Click OK. When supported, clicking the button prompts the user to choose a file to embed under that name.
Add a second button in Prepare a Form. In its Properties, choose Actions > Mouse Up > Run a JavaScript and click Add.
Enter this script: this.exportDataObject({cName: "MyAttachment", nLaunch: 2}); Click OK, save the PDF, and test both buttons in order.

Replace a file attachment comment with a regular attachment
Use this approach if the existing file was added as a comment and the button must open it later.
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 helps make migration easier, but it does not fix or replace Acrobat's JavaScript attachment-button workflow.

Frequently Asked Questions
Can an Acrobat button open a file attachment comment?
Not through the data-object JavaScript workflow. Save the commented file locally, then use an importDataObject action to embed it as a regular named attachment.
How does the open button find the right attachment?
The exportDataObject action uses the cName value to identify the attachment. Set it to the same name used by the importDataObject action.
Why doesn't the attachment open when I click the button?
Check that the attach button ran first and that both scripts use the same cName. Acrobat or Reader security settings, the file type, or the absence of an appropriate application may also prevent launching.
Where do I add JavaScript to an Acrobat form button?
Open Prepare a Form, select the button, and open Properties. On the Actions tab, choose Mouse Up and Run a JavaScript, then click Add.




