Quick Start (SwaRef): Creating multiple PDF files using the web service API

The following Java code creates multiple PDF files for each data record that is located in an XML data file named Loan_data_batch.xml. The files are written to the C:\Adobe\ directory. The PDF files are written to the C:\Adobe folder located on the J2EE application server hosting LiveCycle, not the client computer. (See Creating Multiple Output Files.)

/** 
* Ensure that you create Java proxy files that consume 
    * the Output services  WSDL. You can use JAX-WS to create 
    * the proxy Java files.   
    *  
    * For information, see "Invoking LiveCycle using SwaRef" in Programming with LiveCycle 
    */ 
     
import java.io.*; 
import javax.activation.DataHandler; 
import javax.activation.FileDataSource; 
import javax.xml.ws.BindingProvider; 
import javax.xml.ws.Holder; 
import com.adobe.idp.services.*; 
 
public class CreateBatchFilesSwaRef { 
 
    public static void main(String[] args) { 
             
    try{ 
        // Setting configurations to retrieve the Web service 
        String url = "http://hiro-xp:8080/soap/services/OutputService?blob=swaref"; 
        String username = "administrator"; 
        String password = "password"; 
         
        // Create the service Client objects needed 
        OutputServiceService outService = new OutputServiceService(); 
        OutputService outClient = outService.getOutputService(); 
        // Set authentication values 
        ((BindingProvider) outClient).getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, url); 
        ((BindingProvider) outClient).getRequestContext().put(BindingProvider.USERNAME_PROPERTY, username); 
        ((BindingProvider) outClient).getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, password); 
                                     
        //Create a BLOB object to store form data     
        String path = "C:\\Adobe\Loan_data_batch.xml"; 
        FileDataSource ds = new FileDataSource(path);  
        DataHandler handler = new DataHandler(ds); 
        BLOB inXMLData = new BLOB(); 
        inXMLData.setSwaRef(handler); 
 
        //Set PDF run-time options     
        PDFOutputOptionsSpec outputOptions = new PDFOutputOptionsSpec(); 
        outputOptions.setFileURI("C:\\Adobe\Loan.pdf"); 
        outputOptions.setLookAhead(300); 
        outputOptions.setRecordName("LoanRecord"); 
        outputOptions.setGenerateManyFiles(true); 
                     
        //Set rendering run-time options 
        RenderOptionsSpec pdfOptions = new RenderOptionsSpec();  
        pdfOptions.setLinearizedPDF(true); 
        pdfOptions.setAcrobatVersion(AcrobatVersion.ACROBAT_8); 
                     
        //Create output parameters 
        Holder<BLOB> generatePrintedOutputPrintedDoc = new Holder<BLOB>(); 
        Holder<BLOB> generatePrintedOutputMetaDataDoc = new Holder<BLOB>(); 
        Holder<BLOB> generatePrintedOutputResultDoc = new Holder<BLOB>(); 
        Holder<OutputResult> generatePrintedOutputResult = new Holder<OutputResult>(); 
             
        //Create the batch PDF documents             
        outClient.generatePDFOutput( 
            TransformationFormat.PDF, 
            "Loan.xdp", 
            "C:\\Adobe", 
            outputOptions, 
            pdfOptions, 
            inXMLData, 
            generatePrintedOutputPrintedDoc, 
            generatePrintedOutputMetaDataDoc, 
            generatePrintedOutputResultDoc, 
            generatePrintedOutputResult); 
         
        //Populate a byte array with BLOB data 
        BLOB outDoc = generatePrintedOutputResultDoc.value ;  
        DataHandler handler3 = outDoc.getSwaRef(); 
 
           //Create a new file containing the returned PDF document 
        File f = new File("C:\\Adobe\Output.xml"); 
        InputStream inputStream = handler3.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); 
        out.close(); 
        inputStream.close(); 
 
           System.out.println("The PDF documents were created. The Output.xml file contains the results."); 
     
    }catch (Exception ee) 
    { 
        ee.printStackTrace(); 
    } 
    } 
}

// Ethnio survey code removed