Quick Start (SwaRef): Converting an HTML document to a PDF document using the web service API

The following Java web service example converts HTML content located at http://www.adobe.com to a PDF document named AdobeHTML.pdf. (See Converting HTML Documents to PDF Documents.)

/** 
    * Ensure that you create Java proxy files that consume 
    * the Encryption 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.xml.ws.BindingProvider; 
import javax.xml.ws.Holder; 
import com.adobe.idp.services.*; 
 
public class ConvertHTMLSwaRef { 
 
    public static void main(String[] args) 
    { 
        try { 
            // Setting configurations to retrieve the Web service 
            String url = "http://pdf-generator:8080/soap/services/GeneratePDFService?blob=swaRef"; 
            String username = "administrator"; 
            String password = "password"; 
             
            // Create the service Client objects needed 
            GeneratePDFServiceService pdfgService = new GeneratePDFServiceService(); 
            GeneratePDFService pdfgClient = pdfgService.getGeneratePDFService(); 
             
            // Retrieve the Web services from the LiveCycle Server. 
            ((BindingProvider) pdfgClient).getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, url); 
            ((BindingProvider) pdfgClient).getRequestContext().put(BindingProvider.USERNAME_PROPERTY, username); 
            ((BindingProvider) pdfgClient).getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, password); 
             
            //Reference an HTML docuemnt to convert to a PDF document 
            String inputFileName = "http://www.adobe.com"; 
             
         String securitySettings = "No Security"; 
            String fileTypeSettings = "Standard"; 
             
            //Prepare output parameters 
         Holder<BLOB> createdDocument = new Holder<BLOB>(); 
            Holder<HtmlToPdfResult> result = new Holder<HtmlToPdfResult>(); 
     
            //Convert HTML content to a PDF document 
            pdfgClient.htmlToPDF2( 
                    inputFileName, 
                    fileTypeSettings, 
                    securitySettings, 
                    null, 
                    null, 
                    result, 
                    createdDocument); 
             
            //Save the converted PDF document as a PDF file 
            File f = new File("C:\\Adobe\AdobeHTML.pdf"); 
            DataHandler handler2 = createdDocument.value.getSwaRef(); 
             
            //Get an InputStream from DataHandler and 
            //write to a file 
            InputStream inputStream = handler2.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(); 
        } 
        catch (Exception e) { 
            System.out.println("Error OCCURRED: " + e.getMessage()); 
        } 
    } 
}