• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers

Button to allow user to attach a file

Enthusiast ,
Apr 10, 2015 Apr 10, 2015

Copy link to clipboard

Copied

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?

TOPICS
PDF forms

Views

41.1K

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Apr 11, 2015 Apr 11, 2015

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

...

Likes

Translate

Translate
LEGEND ,
Sep 02, 2016 Sep 02, 2016

Copy link to clipboard

Copied

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.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Mar 21, 2017 Mar 21, 2017

Copy link to clipboard

Copied

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.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 22, 2017 Mar 22, 2017

Copy link to clipboard

Copied

The script controls where the attachment annotation is placed on the page. It defaults to a location off of the page, but you can change this to whatever you want. If you know the coordinates where you want it to appear, I can suggest a revision to the code that you can use.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Mar 22, 2017 Mar 22, 2017

Copy link to clipboard

Copied

Thanks George. I am not sure how to give you coordinates. The PDF page size is 8.5" x 15".

I placed a text box on the PDF and positioned it. The left measurement was 39p0, bottom was 1p0.

Also, this form has three pages. Is the attachment placed on whatever page you place the button? And, there is always the possibility that a user may have more than one attachment.

For my purposes, a hidden text box that becomes visible when an attachment comment is placed on the page would work just as well, too. Just want to make it simple for the users.

Thanks again

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Dec 04, 2017 Dec 04, 2017

Copy link to clipboard

Copied

Hi All,

I'm trying  to add attachment in PDF from using Adobe Livecycle ES 8.2 designer tool.Used the custom script in button click, but it's not working. Please someone quickly advise me and share the custom script to add attachment in button click event.

Script is

  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);

    }

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Feb 13, 2018 Feb 13, 2018

Copy link to clipboard

Copied

Where in Javascript do you post this code? In Document Javascript I already have Javascript for another action item. Can I just add this code to the existing one? I am using Acrobat Pro DC.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 13, 2018 Feb 13, 2018

Copy link to clipboard

Copied

You can add the code to an existing document-level JavaScript, or just add another and place it there.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Feb 15, 2018 Feb 15, 2018

Copy link to clipboard

Copied

Thanks. What's the code that gets pasted into Document Script? So after I copy and paste the button and then add the document script it should work?

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 30, 2018 May 30, 2018

Copy link to clipboard

Copied

George,

The code you posted has been of great help, thank you, particularly as I'm new to JS and I thought I'd done good but of course then realised that no user with just Reader can add attachments "as attachments".

I have a information message added into a textbox for the user so they can see that the file has been added. I can't seem to get this code to work with your helpful example, even though I have replaced with your variable "annot". Could you spare a moment to help please or tell me where to place it in your code?

This is my message code:

this.importDataObject("MyFile");

var annot = this.getDataObject("MyFile");

this.getField("fileName").value = annot.path + " has been added to the document."; // change the field name as needed

Best regards

Rob

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Dec 04, 2017 Dec 04, 2017

Copy link to clipboard

Copied

Hi,

I'm trying  to add attachment in PDF from using Adobe Livecycle ES 8.2 designer tool.Used the custom script in button click, but it's not working. Please someone quickly advise me and share the custom script to add attachment in button click event.

Script is

  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);

    }

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 04, 2017 Dec 04, 2017

Copy link to clipboard

Copied

This code will not work in an LCD form. You should post your question in the relevant forum: LiveCycle Designer

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 09, 2016 Jun 09, 2016

Copy link to clipboard

Copied

I've added the button and it works flawlessly. I see that if I open the document in Reader the files don't show anywhere. They are there, checked with XI just to make sure. Is there a way to show the attachments within the PDF itself instead of just in the attachment pane that don't exist in DC?

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 09, 2016 Jun 09, 2016

Copy link to clipboard

Copied

The files attached using the code above will not appear in the Attachments panel.

They are a part of an annotation (a comment), and will therefore appear in the Comments panel.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Apr 10, 2015 Apr 10, 2015

Copy link to clipboard

Copied

Since that code only works for images, I'll wait until you get a chance to post JavaScript for Reader XI and Reader DC users to attach a file.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 25, 2016 Apr 25, 2016

Copy link to clipboard

Copied

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

    }

}

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 25, 2016 Apr 25, 2016

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 13, 2018 Jun 13, 2018

Copy link to clipboard

Copied

LATEST

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

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines