Quick Start (SwaRef): Creating a PDF/A document using the web service API

The following Java code example creates a PDF/A document named LoanArchive.pdf. This PDF document is based on a form design named Loan.xdp and an XML data file named Loan.xml. The LoanArchive.pdf is written to the C:\Adobe folder located on the J2EE application server hosting LiveCycle, not the client computer. (See Creating PDF/A Documents.)

/** 
    * 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 CreatePDFADocumentSwaRef { 
 
    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.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\LoanArchive.pdf"); 
        outputOptions.setLookAhead(300); 
        outputOptions.setRecordLevel(1); 
             
        //Set rendering run-time options 
        RenderOptionsSpec pdfOptions = new RenderOptionsSpec();  
        pdfOptions.setLinearizedPDF(true); 
        pdfOptions.setAcrobatVersion(AcrobatVersion.ACROBAT_8); 
                 
        //Create Holders for the call to outClient 
        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 a PDFA document             
        outClient.generatePDFOutput( 
            TransformationFormat.PDFA, 
            "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 PDFA 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/A document was created. The Output.xml file contains the results."); 
     
    }catch (Exception ee) 
        { 
            ee.printStackTrace(); 
        } 
    } 
}

// Ethnio survey code removed