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

Add an "Attach File" button to a PDF form.

Community Beginner ,
Jan 04, 2017 Jan 04, 2017

Copy link to clipboard

Copied

I need to add the ability to attach a file to a PDF form. The file type that needs to be attached would most likely be a pdf, docx, or doc (if that matters). I'm working in Acrobat Pro DC, but the form will need to work in Reader as well. I think Java Script can accomplish this, but I have no idea how to write Java.

Thanks in advance for your help!

TOPICS
PDF forms

Views

175.0K

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
1 ACCEPTED SOLUTION
Community Beginner ,
Jan 04, 2017 Jan 04, 2017

Copy link to clipboard

Copied

Here's how to create an "Attach File" button in a form in Acrobat Pro DC (as of Jan. 4, 2017):

1. In Acrobat Pro DC, go to Tools>Prepare Form

2. Add a button to your form by clicking on the "OK" icon and click the desired location on your form for the button.

3. Right click on the button and go to Properties. Set whatever you want in the General, Appearance, Position, and Options tabs.

4. In the Actions tab, under Select Action choose Run a Java Script. Click Add and copy and paste this text:

if (app.viewerVersion < 11) {

    import_pre_11();

} else {

    import_11();

}

5. Close out of Prepare Form mode and go to Tools>Java Script

6. Click on Document Java Scripts, and in Script Name type import_file, click Add, and then copy and paste this text:

// Initialize attachment number

attachment_num = 1;

// Initial location of file attachment icon

// The x value is incremented below

var oFAP = {x_init: -72, x: -72, y: -72};  // Below lower-left corner of the page

function import_pre_11() {

    if (app.viewerType === "Reader") {

        app.alert({

            cMsg: "You must user Reader version 11 or later to attach files to this form.",

            cTitle: "Attach File Error",

            nIcon: 3,

            nType: 0

        });

   

        return;

    }

    // Prompt user to import a file

    app.alert({

        cMsg: "Click the OK/Open button after selecting the file from your system that you want to attach.",

        cTitle: "Attach File",

        nIcon: 3,

        nType: 0

    });

   

    try {

   

        var rc = this.importDataObject("Attachment" + attachment_num);

        if (rc) {

            attachment_num += 1;

            app.alert({

                cMsg: "Attachment successful.\r\rOpen the Attachments panel to access the attached file(s).",

                cTitle: "Attachment Successful",

                nIcon: 3,

                nType: 0

            });

           

        } else {

            app.alert({

                cMsg: "Attachment cancelled.",

                cTitle: "Attachment Cancelled",

                nIcon: 3,

                nType: 0

            });

        }

       

       

    } catch (e) {

        app.alert({

            cMsg: "Could not attach file.",

            cTitle: "Could not attach file",

            nIcon: 3,

            nType: 0

        });

    }

}

function import_11() {

    try {

        var annot = addAnnot({

            page: event.target.page,

            type: "FileAttachment",

            author: "Form user",

            name: "File Attachment",

            point: [oFAP.x, oFAP.y],

            contents: "File attachment on: " + util.printd("yyyy/mm/dd HH:MM:ss", new Date()),

            attachIcon: "Paperclip"

        });

        annot.cAttachmentPath; // Prompt user to select a file to attach

       

        oFAP.x += 18;  // Increment the x location for the icon

       

       

    } catch (e) {

        app.alert({

            cMsg: "Could not attach file.\r\rPlease report this error.",

            cTitle: "File attachment error",

            nIcon: 3,

            nType: 0

        });

    }

   

}

7. And you are done! To view attached documents, go to View>Navigation Pane>Attachments.

Special thanks to George_Johnson​ for his help!

View solution in original post

Votes

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 ,
Jul 26, 2020 Jul 26, 2020

Copy link to clipboard

Copied

You can manually go to the navigation pane>attachments (the menu on the left side) to see existing attachments and add or delete.

OR

I made an action so that when a user clicks the attach button the navigation pane automatically opens.

  1. Click on your button and go to properties
  2. Go to actions
  3. Add an action
    Select trigger: mouse up
    Select action: execute a menu item
  4. Click "add"
  5. In the pop up, scroll down and select "View>Show/Hide>Navigtation Panes>Attachments then click OK

 

Votes

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 ,
Aug 10, 2020 Aug 10, 2020

Copy link to clipboard

Copied

Thank you sooooo very much. It is 2020 and this resource still applies.

Votes

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 ,
Sep 11, 2020 Sep 11, 2020

Copy link to clipboard

Copied

Hi, i need to attach a vcf to a pdf so that a user can click a button and open it. I've tried everything (including the above) and it just links back to my C: drive as the location of the file instead of a file within the document. Once i distribute it the link to my drive will be broken. I've got a big pitch to a law firm in a couple days and would really like this to make it easy for them. I can't do a link to dropbox or other sites because of the strict security. HELP!

Votes

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