Skip to main content
Known Participant
January 30, 2016
Answered

Please help Creating a Detach Button that detaches a document I have attached with an Attach Button

  • January 30, 2016
  • 1 reply
  • 1512 views

Let me apologize up front for this being a bit of complicated question. I found a thread on this forum that helped me attach a file with a click of a button- now I want to detach this same file.  Below is how far I've gotten.   

I created a form in Adobe Acrobat DC that allows a user to attach a document to the form with a click of a button.  The way this is programmed is that on the button itself with a Mouse Up action, the following Javascript is run:

if (app.viewerVersion < 11) {

    import_pre_11();

} else {

    import_11();

}

Then there is a document level javascript for attaching the file that is programmed like this:

// 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 button to select a file from your system.",

        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

        });

    }

   

}

That process works flawlessly.  What I want to do now is detach that same document with the click of another button.  I understand very basic javascript but had help from the forum creating the above script.  Can anyone provide me a solution (if there is one), to help me detach the file that the user attached with the script above? Thank you so much in advance!!!

This topic has been closed for replies.
Correct answer try67

I think you are giving me too much credit for knowing what exactly I'm doing!

I checked the JS console and this is the error message:

TypeError: this.syncAnnotsScan is not a function

1:Field:Mouse Up

There is only one page to the attachment and only one attachment, so do I need to adjust the code?  If so, what part of the code needs to change?

Thank you for your patience with my lack of knowledge!


Sorry, that's my bad... It needs to be:

this.syncAnnotScan();

1 reply

Known Participant
January 30, 2016

If it helps, there will only be one attachment to every form and that attachment will always have the same name of Resume.pdf

Also, I'm just figuring out that most of the script from above is to alert users with old versions of Reader how to attach the file.  For the purpose of deleting the file, I can assume all users will be using the most current version of Reader.

try67
Adobe Expert
January 30, 2016

You can remove an annotation object using its destroy method, but first you need to find it.
Is this file attachment annotation the only one on the page?

Known Participant
January 31, 2016

Sorry, that's my bad... It needs to be:

this.syncAnnotScan();


Once again try67, THANK YOU!  Works perfectly!