Skip to main content
Inspiring
April 11, 2015
Answered

Button to allow user to attach a file

  • April 11, 2015
  • 3 replies
  • 53179 views

I need to create a button or link that allows a Reader user to click and attach a resume file. Most attachments will probably be Word documents.

Using Acrobat Pro XI, is it possible to add that type of button to a form?

This topic has been closed for replies.
Correct answer George_Johnson

George, I truly appreciate your help on this and will look for your post later today.


Here's a link to a sample document: Dropbox - importTest_20150411_1.pdf

It contains a single button that uses some JavaScript, most of which is contained in a document-level JavaScript. You'll have to study it a bit to figure out how it works. It relies on using the cAttachmentPath annotation property, which really acts like a method to prompt the user to attach a file. If Acrobat is used and it's prior to 11, the normal type of file attachment is used, but this won't work with Reader unless the document has file attachment usage rights applied by LiveCycle Reader Extensions, which I don't think you have.

It is currently set up to add the attachment icons (when used with Acrobat/Reader 11 or greater) below and to the left of the bottom left corner of the page, so they usually won't be visible as they would be when a user manually adds a file attachment as a comment (annotation). Any comment attachments that are added will appear in the Attachments pane.

3 replies

New Participant
June 13, 2018

This "Attach File" button script works great... but I want to use it together with the PDF form 'image field' that uses the script:

event.target.buttonImportIcon();

How can I combine it with your script so it will show the image and attach it in the same time:

if (app.viewerVersion < 11) {

    import_pre_11();

} else {

    import_11();

}

Thanks, JanB

kellya41859936
New Participant
April 25, 2016

Hello.

I was able to get this code to work, to add one file.  Is there a way to attach multiple files?

try {

    var annot = this.addAnnot({

        page: 0,

        type: "FileAttachment",

        point: [500, 500],

        noView: true,

        author: "Attachment"

    });

    annot.cAttachmentPath;

    var attachmentObj = annot.attachment;

    if (attachmentObj !== null) {

        app.alert("Add this file: " + attachmentObj.name);

        var l = this.getField("lst1");

        l.insertItemAt(attachmentObj.name, 0);

    }

}

catch(e) {

    if (e.name == "NotAllowedError") {

        // do nothing

    }

}

try67
Braniac
April 25, 2016

Run the same code multiple times. You can do it in a for-loop.

Inspiring
April 11, 2015

It's only possible to do with a button if the users will have Reader 11 or the new DC, or you're able to Reader-enable the document with LiveCycle Reader Extensions. If it has to work with earlier versions, users will be able to manually attach files using the "Attach File" commenting tool. With Reader 11/DC, it will require some JavaScript to work with a button. Post again if you need help with the scripting.

Inspiring
April 11, 2015

George,

Thanks so much for your reply, and thanks for offering to help with the JavaScript -- I will need help with that.

I'll be using Acrobat XI Pro to create the form. I could possibly use Acrobat DC, but I don't know anything about that version.

  • Will Reader 11 users or Reader DC users be able to attach any type of file or does it have to be a PDF? (As I mentioned, most will probably be attaching Word documents.)
  • Will the JavaScript work on Mobile devices so that users can attach a file from a mobile device?
  • If a form is already created in Acrobat XI Pro, with all the form fields already created, can the form then be converted to an Acrobat DC form?
Inspiring
March 22, 2017

If all you did was copy the code from the button, then it won't work. You also need to include the code that's in the document-level JavaScript, which is what the code in the button's Mouse Up event calls.


Hi

This script is working fine for me, I can see the attachments in the attachment panel.

I was wondering someone could tell me how to indicate to the person viewing the PDF that there is an attachment(s) on the PDF. Maybe a hidden text field that becomes visible when attachments are present? Is this possible? Or is the fix to change the document level script to put the attachment icons on the page vs "below and to the left of the bottom left corner of the page"

Thanks in advance for any ideas on this.