PDF Editing Issues

Create an Acrobat Button to Attach and Open a File

Camila MilosovichCamila Milosovich Nov 19, 2026 868 views

Question details

Create an Acrobat button workflow that attaches a file to a PDF and opens the same attachment later.

Create an Acrobat Button to Attach and Open a File
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.
Before you start

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.

Solution 1Recommended

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.

1
Create the attach button

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.

2
Add the import action

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.

3
Create the open button

Add a second button in Prepare a Form. In its Properties, choose Actions > Mouse Up > Run a JavaScript and click Add.

4
Open the named attachment

Enter this script: this.exportDataObject({cName: "MyAttachment", nLaunch: 2}); Click OK, save the PDF, and test both buttons in order.

Use Acrobat JavaScript buttons with a data-object attachment
Security and compatibility: JavaScript, attachment import, and launching embedded files may be restricted by the Acrobat or Reader version, security settings, or file type. Opening the attachment may also require a suitable application.
Free Microsoft Office alternative

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.

Open and review PDF documents alongside your other filesCompatible with Microsoft Word, Excel, and PowerPoint formatsFamiliar interface for a smoother move from Microsoft OfficeFree and lightweight tools for everyday document work
microsoft office alternative - wps office

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.