Quick Start (Java SWAref): Assembling an encrypted PDF document using the web service API

The following Java code example assembles a password-encrypted PDF document. The unsecured PDF document is named Loan.pdf. Notice that the name of the DDX document is shell_Encrypt.xml. The encrypted PDF document is named AssemblerEncryptedPDF.pdf. The encrypted PDF document is named AssemblerEncryptedPDF.pdf. (See Assembling Encrypted 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.  
    *  
    *  The following XML represents the DDX document used in this quick start: 
    *<?xml version="1.0" encoding="UTF-8"?> 
    *  <DDX xmlns="http://ns.adobe.com/DDX/1.0/"> 
    *   <PDF result="EncryptLoan.pdf" encryption="userProtect"> 
    *        <PDF source="inDoc" /> 
    *    </PDF> 
    *    <PasswordEncryptionProfile name="userProtect" compatibilityLevel="Acrobat7"> 
    *        <OpenPassword>AdobeOpen</OpenPassword> 
    *   </PasswordEncryptionProfile> 
    * </DDX> 
    */ 
 
import java.io.*; 
 
import javax.activation.DataHandler; 
import javax.activation.FileDataSource; 
import javax.xml.ws.BindingProvider; 
 
import com.adobe.idp.services.*; 
 
public class AssembleEncryptedDocSWAref { 
     
    public static void main(String[] args){ 
         
        try{ 
            //Create an AssemblerServiceService object 
            AssemblerServiceService assembler = new AssemblerServiceService(); 
            AssemblerService assembClient = assembler.getAssemblerService(); 
             
            //Set connection values required to invoke LiveCycle 
            String url = "http://hiro-xp:8080/soap/services/AssemblerService?blob=swaRef"; 
            String username = "administrator"; 
            String password = "password"; 
            ((BindingProvider) assembClient).getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, url); 
            ((BindingProvider) assembClient).getRequestContext().put(BindingProvider.USERNAME_PROPERTY, username); 
            ((BindingProvider) assembClient).getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, password); 
             
               // Create BLOB objects that represents the input  
               // DDX file and the unsecured PDF document 
            String path = "C:\\shell_Encrypt.xml"; 
            FileDataSource ds = new FileDataSource(path);  
            DataHandler handler = new DataHandler(ds); 
            BLOB ddxDoc = new BLOB(); 
            ddxDoc.setSwaRef(handler); 
             
            String path2 = "C:\\Adobe\Loan.pdf"; 
            FileDataSource ds2 = new FileDataSource(path2);  
            DataHandler handler2 = new DataHandler(ds2); 
            BLOB LoanDoc = new BLOB(); 
            LoanDoc.setSwaRef(handler2); 
             
               // Create an AssemblerOptionsSpec object 
               AssemblerOptionSpec assemblerSpec = new AssemblerOptionSpec(); 
               assemblerSpec.setFailOnError(false); 
 
               // Send the request to the Assembler Service 
               BLOB outDoc = assembClient.invokeOneDocument(ddxDoc, LoanDoc, assemblerSpec); 
 
               //Populate a byte array with BLOB data 
               DataHandler handler3 = outDoc.getSwaRef(); 
 
               //Create a new file containing the returned PDF document 
            File f = new File("C:\\AssembleEncryptedPDF.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(); 
 
               System.out.println("The encrypted PDF document was assembled."); 
        } 
        catch(Exception e) 
        { 
            e.printStackTrace(); 
        } 
     
    } 
 
} 

// Ethnio survey code removed