Quick Start (SOAP mode): Dynamically creating a DDX document using the Java API

The following Java code example dynamally creates a DDX document that disassembles a PDF document. A new PDF document is created for each level 1 bookmark in the input PDF document. This code example contains two user-defined methods:

  • createDDX: Creates an org.w3c.dom.Document object that represents the DDX document that is sent to the Assembler service. This user-defined method returns the org.w3c.dom.Document object.

  • convertDDX: Converts an org.w3c.dom.Document object to a com.adobe.idp.Document object. This method accepts an org.w3c.dom.Document object as an input parameter and returns a com.adobe.idp.Document object.

    Both of these methods are invoked in this quick start. (See Dynamically Creating DDX Documents.)

        * This Java Quick Start uses the SOAP mode and contains the following JAR files 
        * in the class path: 
        * 1. adobe-assembler-client.jar 
        * 2. adobe-livecycle-client.jar 
        * 3. adobe-usermanager-client.jar 
        * 4. adobe-utilities.jar 
        * 5. jbossall-client.jar (use a different JAR file if the LiveCycle Server is not deployed 
        * on JBoss) 
        * 6. activation.jar (required for SOAP mode) 
        * 7. axis.jar (required for SOAP mode) 
        * 8. commons-codec-1.3.jar (required for SOAP mode) 
        * 9.  commons-collections-3.1.jar  (required for SOAP mode) 
        * 10. commons-discovery.jar (required for SOAP mode) 
        * 11. commons-logging.jar (required for SOAP mode) 
        * 12. dom3-xml-apis-2.5.0.jar (required for SOAP mode) 
        * 13. jaxen-1.1-beta-9.jar (required for SOAP mode) 
        * 14. jaxrpc.jar (required for SOAP mode) 
        * 15. log4j.jar (required for SOAP mode) 
        * 16. mail.jar (required for SOAP mode) 
        * 17. saaj.jar (required for SOAP mode) 
        * 18. wsdl4j.jar (required for SOAP mode) 
        * 19. xalan.jar (required for SOAP mode) 
        * 20. xbean.jar (required for SOAP mode) 
        * 21. xercesImpl.jar (required for SOAP mode) 
        * These JAR files are located in the following path: 
        * <install directory>/sdk/client-libs/common 
        * The adobe-utilities.jar file is located in the following path: 
        * <install directory>/sdk/client-libs/jboss 
        * The jbossall-client.jar file is located in the following path: 
        * <install directory>/jboss/client 
        * SOAP required JAR files are located in the following path: 
        * <install directory>/sdk/client-libs/thirdparty 
        * If you want to invoke a remote LiveCycle Server instance and there is a 
        * firewall between the client application and the server, then it is  
        * recommended that you use the SOAP mode. When using the SOAP mode,  
        * you have to include these additional JAR files 
        * For information about the SOAP  
        * mode, see "Setting connection properties" in Programming  
        * with LiveCycle 
        * The following XML represents the DDX document created in this quick start: 
        * <?xml version="1.0" encoding="UTF-8"?> 
        * <DDX xmlns="http://ns.adobe.com/DDX/1.0/"> 
        * <PDF result="out.pdf"> 
        *   <PDF source="inDoc"/> 
        *   <NoXFA/> 
        * </PDF> 
        * </DDX> 
    import com.adobe.livecycle.assembler.client.*; 
    import java.util.*; 
    import java.io.ByteArrayOutputStream; 
    import java.io.File; 
    import java.io.FileInputStream; 
    import javax.xml.parsers.DocumentBuilder; 
    import javax.xml.parsers.DocumentBuilderFactory; 
    import javax.xml.transform.Transformer; 
    import javax.xml.transform.TransformerFactory; 
    import javax.xml.transform.dom.DOMSource; 
    import javax.xml.transform.stream.StreamResult; 
    import org.w3c.dom.Element; 
    import com.adobe.idp.Document; 
    import com.adobe.idp.dsc.clientsdk.ServiceClientFactory; 
    import com.adobe.idp.dsc.clientsdk.ServiceClientFactoryProperties; 
    public class AssemblePDFWithDynamicDDXSOAP 
        public static void main(String[] args) { 
                //Set connection properties required to invoke LiveCycle using SOAP mode                                 
                Properties connectionProps = new Properties(); 
                connectionProps.setProperty(ServiceClientFactoryProperties.DSC_DEFAULT_SOAP_ENDPOINT, "http://hiro-xp:8080"); 
                connectionProps.setProperty(ServiceClientFactoryProperties.DSC_SERVER_TYPE, "JBoss"); 
                connectionProps.setProperty(ServiceClientFactoryProperties.DSC_CREDENTIAL_USERNAME, "administrator"); 
                connectionProps.setProperty(ServiceClientFactoryProperties.DSC_CREDENTIAL_PASSWORD, "password"); 
                //Create a ServiceClientFactory instance 
                ServiceClientFactory myFactory = ServiceClientFactory.createInstance(connectionProps); 
                //Create an AssemblerServiceClient object 
                AssemblerServiceClient assemblerClient = new AssemblerServiceClient(myFactory); 
                //Dynamically create a DDX document 
                org.w3c.dom.Document myDDX= createDDX() ;  
                //Covert the DDX document to a com.adobe.idp.Document instance     
                com.adobe.idp.Document ddx = convertDDX(myDDX); 
                //Create a Map object to store PDF source documents 
                Map inputs = new HashMap(); 
                FileInputStream mySourceMap = new FileInputStream("C:\\AssemblerResultPDF.pdf"); 
                //Create a Document object based on the map.pdf source file 
                Document myPDFSource = new Document(mySourceMap);  
                //Place the entry into the Map object 
                //Create an AssemblerOptionsSpec object 
                AssemblerOptionSpec assemblerSpec = new AssemblerOptionSpec(); 
                //Submit the job to Assembler service and use the dynamically created DDX document 
                AssemblerResult jobResult = assemblerClient.invokeDDX(ddx,inputs,assemblerSpec);    
                java.util.Map allDocs = jobResult.getDocuments(); 
                //Retrieve the result PDF document from the Map object 
                Document outDoc = null; 
                int index = 1; 
                //Iterate through the map object to retrieve the result PDF documents 
                for (Iterator i = allDocs.entrySet().iterator(); i.hasNext();) { 
                    // Retrieve the Map object's value 
                    Map.Entry e = (Map.Entry)i.next(); 
                    Object o = e.getValue(); 
                    //Cast the Object to a Document 
                    //and save to a file     
                    outDoc = (Document)o; 
                    File myOutFile = new File("C:\\ResultPDF"+index +".pdf"); 
            }catch (Exception e) { 
         //Creates a DDX document using an org.w3c.dom.Document object 
         private static org.w3c.dom.Document createDDX() 
            org.w3c.dom.Document document = null; 
                //Create DocumentBuilderFactory and DocumentBuilder objects 
                DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); 
                DocumentBuilder builder = factory.newDocumentBuilder(); 
                //Create a new Document object 
                document = builder.newDocument();  
                //Create the root element and append it to the XML DOM 
                Element root = (Element)document.createElement("DDX"); 
                //Create the PDFsFromBookmarks element 
                Element PDFsFromBookmarks = (Element)document.createElement("PDFsFromBookmarks"); 
                //Create the PDF element 
                Element PDF = (Element)document.createElement("PDF"); 
         catch (Exception e) { 
                  System.out.println("The following exception occurred: "+e.getMessage()); 
        return document; 
         //Converts an org.w3c.dom.Document object to a  
         //com.adobe.idp.Document object  
         private static Document convertDDX(org.w3c.dom.Document myDOM) 
            byte[] mybytes = null;  
            //Create a Java Transformer object 
            TransformerFactory transFact = TransformerFactory.newInstance(); 
            Transformer transForm = transFact.newTransformer();  
            //Create a Java ByteArrayOutputStream object 
            ByteArrayOutputStream myOutStream = new ByteArrayOutputStream();  
            //Create a Java Source object 
            javax.xml.transform.dom.DOMSource myInput = new DOMSource(myDOM); 
            //Create a Java Result object 
            javax.xml.transform.stream.StreamResult myOutput = new StreamResult(myOutStream);      
            //Populate the Java ByteArrayOutputStream object 
            // Get the size of the ByteArrayOutputStream buffer 
             int myByteSize = myOutStream.size(); 
            //Allocate myByteSize to the byte array 
             mybytes = new byte[myByteSize]; 
            //Copy the content to the byte array 
             mybytes = myOutStream.toByteArray(); 
            catch (Exception e) { 
              System.out.println("The following exception occurred: "+e.getMessage()); 
         //Create a com.adobe.idp.Document object and copy the  
         //contents of the byte array 
         Document myDocument = new Document(mybytes); 
         return myDocument;  

// Ethnio survey code removed