Quick Start (Java SWAref): Assembling a PDF document using the web service API

The following Java code example merges two PDF source documents named map.pdf and directions.pdf into a single PDF document. The name of the single PDF document is AssemblerResultPDF.pdf. The name of the DDX document is shell.xml. (See Programmatically Assembling PDF Documents.)

    * Ensure that you create Java proxy files that consume 
    * the Assembler services WSDL. You can use JAX-WS to create 
    * the proxy Java files.   
    * For information, see "Invoking LiveCycle using SwaRef" in Programming with LiveCycle 
    *This quick start validates the following DDX document: 
    *<?xml version="1.0" encoding="UTF-8"?> 
    * <DDX xmlns="http://ns.adobe.com/DDX/1.0/"> 
    *    <PDF result="out.pdf"> 
    *        <PDF source="map.pdf" /> 
    *        <PDF source="directions.pdf" /> 
    *    </PDF> 
    * </DDX> 
import java.io.*; 
import java.util.*; 
import javax.activation.DataHandler; 
import javax.activation.FileDataSource; 
import javax.xml.ws.BindingProvider; 
import org.apache.xml.xml_soap.*; 
import com.adobe.idp.services.*; 
public class AssemblePDFSWAref { 
    public static void main(String[] args)  
            //Create an AssemblerService object 
            AssemblerServiceService assembler = new AssemblerServiceService(); 
            AssemblerService assembClient = assembler.getAssemblerService(); 
            //Set connection values required to invoke LiveCycle 
            String url = "http://hiro-xp:8080/soap/services/AssemblerService?blob=swaRef"; 
            String username = "administrator"; 
            String password = "password"; 
            ((BindingProvider) assembClient).getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, url); 
            ((BindingProvider) assembClient).getRequestContext().put(BindingProvider.USERNAME_PROPERTY, username); 
            ((BindingProvider) assembClient).getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, password); 
            //Retrieve the input DDX and the PDF documents to assemble 
            String path = "C:\\shell.xml"; 
            FileDataSource ds = new FileDataSource(path);  
            DataHandler handler = new DataHandler(ds); 
            BLOB ddx = new BLOB(); 
            String path2 = "C:\\map.pdf"; 
            FileDataSource ds2 = new FileDataSource(path2);  
            DataHandler handler2 = new DataHandler(ds2); 
            BLOB doc1 = new BLOB(); 
            String path3 = "C:\\directions.pdf"; 
            FileDataSource ds3 = new FileDataSource(path3);  
            DataHandler handler3 = new DataHandler(ds3); 
            BLOB doc2 = new BLOB(); 
            // Create the map containing the PDF source documents 
            MyMapOfXsdStringToXsdAnyType inputMap = new MyMapOfXsdStringToXsdAnyType(); 
            List<MyMapOfXsdStringToXsdAnyTypeItem> inputMapItemList = inputMap.getItem(); 
            MyMapOfXsdStringToXsdAnyTypeItem doc1Item = new MyMapOfXsdStringToXsdAnyTypeItem(); 
            MyMapOfXsdStringToXsdAnyTypeItem doc2Item = new MyMapOfXsdStringToXsdAnyTypeItem();     
            // Create an AssemblerOptionsSpec object 
            AssemblerOptionSpec assemblerSpec = new AssemblerOptionSpec(); 
            // Send the request to the Assembler Service 
            AssemblerResult result = assembClient.invoke(ddx,inputMap,assemblerSpec); 
            // Extract the newly created PDF document from the returned map 
            BLOB outDoc = null; 
            List<MapItem> mapResult = result.getDocuments().getItem(); 
            Iterator<MapItem> rit = mapResult.iterator(); 
                MapItem resultItem = rit.next(); 
                String myKey = (String)(resultItem.getKey()); 
                if (myKey.equals("out.pdf")) 
                    outDoc = (BLOB)(resultItem.getValue()); 
            //Create a PDF file that represents the assembled document 
            File f = new File("C:\\AssemblerResultPDF.pdf"); 
            BLOB outBlob = outDoc; 
            DataHandler handler4 = outBlob.getSwaRef(); 
            //Get an InputStream from DataHandler and 
            //write to the PDF file 
            InputStream inputStream = handler4.getInputStream(); 
            OutputStream out = new FileOutputStream(f); 
            //Iterate through the buffer 
            byte buf[] = new byte[1024]; 
            int len; 
            while ((len = inputStream.read(buf)) > 0) 
                out.write(buf, 0, len); 
        catch(Exception e) 

// Ethnio survey code removed