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

The following Java web service example converts a PDF document called Loan.pdf to a PostScript document called Loan.ps. (See Converting PDF Documents to PostScript.)

/** 
    * Ensure that you create Java proxy files that consume 
    * the Convert PDF 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 java.io.InputStream; 
 
import javax.activation.DataHandler; 
import javax.activation.FileDataSource; 
import javax.xml.ws.BindingProvider; 
 
import com.adobe.idp.services.*; 
 
public class ConvertPDFToPSSwaRef { 
     
       public static void main(String[] args) { 
        try { 
            //Set values required to invoke LiveCycle using SwaRef 
            String url = "http://hiro-xp:8080/soap/services/convertpdfService?blob=swaRef"; 
            String username = "administrator"; 
            String password = "password"; 
             
            //Create a ConvertPdfService object 
            ConvertPdfServiceService convertPdfService = new ConvertPdfServiceService(); 
            ConvertPdfService convClient =  convertPdfService.getConvertPDFService(); 
 
            //Specify authentication values 
            ((BindingProvider) convClient).getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, url); 
            ((BindingProvider) convClient).getRequestContext().put(BindingProvider.USERNAME_PROPERTY, username); 
            ((BindingProvider) convClient).getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, password); 
                         
               //Create a BLOB that represents the input PDF file 
            String path = "C:\\Adobe\Loan.pdf"; 
            FileDataSource ds = new FileDataSource(path);  
            DataHandler handler = new DataHandler(ds); 
            BLOB inDoc = new BLOB(); 
            inDoc.setSwaRef(handler); 
             
               //Create a ToPSOptionsSpec object that defines run-time options 
               ToPSOptionsSpec psSpec = new ToPSOptionsSpec(); 
               psSpec.setPsLevel(PSLevel.LEVEL_3); 
 
               //Send the conversion request to the ConvertPDF Service 
               BLOB outDoc = convClient.toPS2(inDoc, psSpec); 
 
               //Create a new file containing the returned PS document 
            File f = new File("C:\\Adobe\Loan.ps"); 
            BLOB outBlob = outDoc; 
            DataHandler handler2 = outBlob.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(); 
               System.out.println("The PDF file was converted to a PostScript document."); 
           } 
 
           catch (Exception ee) 
           { 
         ee.printStackTrace(); 
           } 
       } 
} 
 
 

// Ethnio survey code removed