3 Replies Latest reply on Mar 12, 2014 2:35 AM by try67

    Remove attachments from attachments

    dcidev Level 4

      Hello all,

      I have a script in my PDF to add Attachment A.pdf. I was wondering if it was possible to remove attachments from Attachment A.pdf before embedding it into the PDF.

       

      I assume I require a priviledged context to perform that action.

       

      Thanks.

       

      Kyle

        • 1. Re: Remove attachments from attachments
          try67 MVP & Adobe Community Professional

          Actually, you don't need a privileged context to do this... This method

          does the trick:

           

          this.removeDataObject("Attachment A.pdf");

          • 2. Re: Remove attachments from attachments
            dcidev Level 4

            Thank you for your reply Gilad D.

             

            I'll explain myself further.

             

            Using scripting the user attaches Attachment A.pdf to Form1.pdf.

            Attachment A.pdf has its own embedded file called Attachment B.pdf.

             

            How do I remove Attachment B.pdf?

             

            I can get the Doc object of Attachment A.pdf with the method openDataObject(). Then I can remove Attachment B.pdf with removeDataObject(). But it seams that I would then have to Save Attachment A.pdf back into Form1.pdf in order for those changes to persist.

             

            Here is an example of the script I use (see comments):

             

            this.importDataObject("Attachment A.pdf");
            oDataDoc = this.openDataObject("Attachment A.pdf");
            DataObj = oDataDoc.dataObjects;
            if (DataObj != null) {
                for (var i = 0; i < DataObj.length; i++) {
                    oDataDoc.removeDataObject(DataObj[i].name);
                    //Remove Attachment B.pdf
                }
                //At this point there are no more embedded files in Attachment A.pdf
            }
            oDataDoc.closeDoc(true);
            //Closes Attachment A.pdf without saving therefore Attachment B.pdf still exists in Attachment A.pdf
            

             

            Kyle

            • 3. Re: Remove attachments from attachments
              try67 MVP & Adobe Community Professional

              That will be tricky... You will need to:

              - Open Attachment A (requires a trusted function).

              - Remove Attachment B.

              - Save Attachment A as a local file (requires a trusted function).

              - Attach Attachment A back to the main file (requires a trusted function).