Quick Start (SwaRef): Transforming a PDF document using the web service API

The following Java code example transforms an interactive PDF document named Loan.pdf into a non-interactive PDF document namedNonInteractiveLoan.pdf. (See Flattening PDF 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 com.adobe.idp.services.*; 
 
public class TransformPDFSwaRef { 
 
    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.pdf"; 
        FileDataSource ds = new FileDataSource(path);  
        DataHandler handler = new DataHandler(ds); 
        BLOB inDoc = new BLOB(); 
        inDoc.setSwaRef(handler); 
             
        //Flatten the PDF document         
        BLOB outDoc = outClient.transformPDF( 
                inDoc, 
                TransformationFormat.PDF, 
                null, 
                null, 
                null); 
         
        //Save the non-interactive PDF document 
        DataHandler handler3 = outDoc.getSwaRef(); 
 
           //Create a new file containing the returned PDF document 
        File f = new File("C:\\Adobe\NonInteractiveLoan.pdf"); 
        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(); 
     
    }catch (Exception ee) 
        { 
            ee.printStackTrace(); 
        } 
    } 
} 

// Ethnio survey code removed