2 Replies Latest reply: Aug 25, 2014 10:42 PM by Sri80 RSS

    FileAttachments in Execute Script

    Sri80 Community Member

      How to add attachments to generated PDF document (i.e. MainForm) and send it to a mail in a ALC process?

       

      Here, my script below

       

      import java.util.Map;

      import java.util.HashMap;

      import java.lang.String;

      import java.lang.StringBuilder;

      import java.util.List;

      import com.adobe.idp.Document;

       

       

      String QUOTE = "\"";

       

       

      quote( String s ) {

        return  QUOTE + s + QUOTE;

      }

       

       

      generateDDX() {

       

       

      List attachList = patExecContext.getProcessDataListValue("/process_data/attachments1");

       

      Document parentDocument = patExecContext.getProcessDataDocumentValue("/process_data/formDoc");

      String documentName = parentDocument.getAttribute("basename");

       

       

      final StringBuilder ddx = new StringBuilder();

      final String newLine = "\n";

       

       

      ddx.append( "<?xml version=" ).append( quote("1.0" ) ).append( " encoding=" ) .append( quote( "UTF-8") ).append(  "?>"  ).append( newLine );

      ddx.append( "<DDX xmlns=" ).append( this.quote( "http://ns.adobe.com/DDX/1.0/" ) ).append( ">" ).append( newLine );

      ddx.append( "<PDF result=" ).append( this.quote( "out.pdf" )).append( ">" ).append( newLine );

      ddx.append( "<PDF source=" ).append( this.quote( "in.pdf" )  ).append(">").append( newLine );

      ddx.append( "<NoForms/>" ).append( newLine );

      ddx.append( "<NoXFA/>" ).append( newLine );

       

      Map documents = new HashMap();

      for (int i=0; i<attachList.size(); i++) {

       

      Document document = (Document)attachList.get(i);

      String currentFileName = document.getAttribute("basename");

       

      ddx.append( "<FileAttachments source=" ).append( this.quote( currentFileName ) ).append(  ">" ).append( newLine );

      ddx.append( "<File filename=" ).append( this.quote( currentFileName )  ).append(  "/>" ).append( newLine );

      ddx.append( "<FilenameEncoding encoding=" ) .append( this.quote( "UTF-8" )  ).append(  "/>" ).append( newLine );

      ddx.append( "</FileAttachments>").append( newLine );

       

      documents.put(currentFileName, document);

      }

       

      patExecContext.setProcessDataMapValue("/process_data/documents", documents);

      ddx.append( "</PDF>\n</PDF>\n</DDX>\n" );

      patExecContext.setProcessDataStringValue( "/process_data/@AssemblerDDX", ddx.toString() );

      }

       

      this.generateDDX();

       

      Error Message:

      Capture.JPG

        • 1. Re: FileAttachments in Execute Script
          Aditaya Maini Community Member

          Hi , Could you please print the ddx in log file and check it, if its correctly build. ( paste the log snippet & build DDX in case its still not working - the image and details of error message above are not clear.) , i just tried below DDX, & its work fine for me.

          Using workbench process variables, so if you are using WB execute script, below is a simple, sample script I used, where I have attachments in a list. kindly test with a simple use case like below & i hope it helps.

          if there are  attachments in list,

          > get the filename and mimetype ,

          >put the sourceDoc in map with numeric key

          > put attachmentDocs with numericKey,  appended by 1,  (so you can iterate here to append all documents of list)

          > then you can build the DDX in execute script like:

           

          import java.util.*;

          import java.util.Iterator;

          List mimetype = patExecContext.getProcessDataListValue("/process_data/attachmentsMimeType");

          List fileNames = patExecContext.getProcessDataListValue("/process_data/attachmentsNameslist");

          HashMap myMap =patExecContext.getProcessDataMapValue("/process_data/assemblerMap");

          System.out.println("***** About to generate DDX***********************");

           

          String ddx = "<DDX xmlns='http://ns.adobe.com/DDX/1.0/'>\n";

          ddx += "<PDF result='finalPDF.pdf'>\n";

          ddx = ddx +  "<PDF source='sourceDoc'/>\n";

           

          for (int i=1;i<myMap.size();i++){

                 ddx = ddx +  "<FileAttachments source = '" + i + "'>\n";

                 ddx = ddx + "<File filename= '" +fileNames.get(i-1)+ "'  mimetype= ' " + mimetype.get(i-1) + "'/>\n";

                 ddx = ddx+ "</FileAttachments>\n";

                 }

           

          ddx = ddx + "</PDF>\n</DDX>\n";

          System.out.println("***** ddx: " + ddx);

          patExecContext.setProcessDataStringValue("/process_data/@ddxString ", ddx);

           

          paste the log snippet & build DDX in case its still not working

          • 2. Re: FileAttachments in Execute Script
            Sri80 Community Member

            Thank You Aditaya Maini.

            It's Working for me.