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

The following Java web service code example converts a PostScript file called Loan.ps to a PDF document calledLoan.pdf. (See Converting PostScript to 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.   
    */ 
 
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 JavaAPICreatePDFSwaRef { 
    public static void main(String[] args){ 
         
        try{ 
            //Create a DistillerService object 
            DistillerServiceService distiller = new DistillerServiceService(); 
            DistillerService distillerClient = distiller.getDistillerService(); 
             
            //Set connection values required to invoke LiveCycle 
            String url = "http://hiro-xp:8080/soap/services/DistillerService?blob=swaRef"; 
            String username = "administrator"; 
            String password = "password"; 
            ((BindingProvider) distillerClient).getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, url); 
            ((BindingProvider) distillerClient).getRequestContext().put(BindingProvider.USERNAME_PROPERTY, username); 
            ((BindingProvider) distillerClient).getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, password); 
             
            //Create a BLOB that represents the input PS file 
               BLOB inDoc = new BLOB(); 
            String path2 = "C:\\Adobe\Loan.ps"; 
            FileDataSource ds2 = new FileDataSource(path2);  
            DataHandler handler2 = new DataHandler(ds2); 
            inDoc.setSwaRef(handler2); 
             
             //Specify the PDF and security settings 
               String adobePDFSettings = "Standard"; 
               String securitySettings = "No Security"; 
 
               //Prepare output parameters 
               Holder<BLOB> createdDocument = new Holder<BLOB>(); 
             Holder<BLOB> logDocument = new Holder<BLOB>(); 
             Holder distillerResult = new Holder(); 
     
               //Send the request to the Distiller Service 
             distillerClient.createPDF2( 
                       inDoc, 
                       path2, 
                       adobePDFSettings, 
                       securitySettings, 
                       null, 
                       null, 
                       distillerResult, 
                       createdDocument, 
                       logDocument); 
 
 
               //Extract the newly created PDF document 
         File f = new File("C:\\Adobe\Loan.pdf"); 
            DataHandler handler4 = createdDocument.value.getSwaRef(); 
             
            //Get an InputStream from DataHandler and 
            //write to a 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); 
            out.close(); 
            inputStream.close(); 
 
               System.out.println("The PS file was converted to a PDF file.");             
        } 
        catch(Exception e) 
        { 
            e.printStackTrace(); 
        } 
    } 
}

// Ethnio survey code removed