Skip to main content
Participating Frequently
March 4, 2025
Question

How can I create an upload button in PDF form?

  • March 4, 2025
  • 3 replies
  • 2551 views



I've use this code bellow:

// 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

        });

 

    }

   

}

3 replies

JR Boulay
Community Expert
Community Expert
March 5, 2025

You shouldn't use the title alone, as in line 10 of your script, because Acrobat for Mac doesn't display the title in an alert. Always use the body of the alert.

cTitle: "Attach File Error",

 

Acrobate du PDF, InDesigner et Photoshopographe
JR Boulay
Community Expert
Community Expert
March 5, 2025

You can embed the form in a PDF-Portfolio to be sure that it will not be used with a low end PDF reader that don't support Javascript:

https://helpx.adobe.com/acrobat/using/create-customize-pdf-portfolios.html

Acrobate du PDF, InDesigner et Photoshopographe
Participating Frequently
March 4, 2025

and this to run as javascript:

if (app.viewerVersion < 11) {

    import_pre_11();

} else {

    import_11();

}

Thom Parker
Community Expert
Community Expert
March 4, 2025

Did you have a question?

 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
Participating Frequently
March 4, 2025

Yes, I'm creating an pdf fillable and I want to sent to my costumers for having thier documents in my database, and for that I need to creat a button that allows to them to upload their files into my pdf file.

 

Do you have any topics related to it please?

 

Kind regards