Quick Start (EJB mode): Applying a policy to a PDF document using the Java API

The following Java Code example applies a policy named Allow Copy to a PDF named Load.pdf. The Policy Set to which the policy is added is named Global Policy Set. The policy-protected document is saved as a PDF named PolicyProtectedLoanDoc.pdf. (See Applying Policies to PDF Documents.)

/* 
 * This Java Quick Start uses the following JAR files 
 * 1. adobe-rightsmanagement-client.jar 
 * 2. namespace.jar (if LiveCycle ES is deployed on JBoss) 
 * 3. jaxb-api.jar (if LiveCycle ES is deployed on JBoss) 
 * 4. jaxb-impl.jar (if LiveCycle ES is deployed on JBoss) 
 * 5. jaxb-libs.jar (if LiveCycle ES is deployed on JBoss) 
 * 6. jaxb-xjc.jar (if LiveCycle ES is deployed on JBoss) 
 * 7. relaxngDatatype.jar (if LiveCycle ES is deployed on JBoss) 
 * 8. xsdlib.jar (if LiveCycle ES is deployed on JBoss) 
 * 2. adobe-livecycle-client.jar 
 * 3. adobe-usermanager-client.jar 
 * 4. adobe-utilities.jar 
 * 5. jbossall-client.jar (use a different JAR file if LiveCycle ES is not deployed on JBoss) 
 * 
 * These JAR files are located in the following path: 
 * <install directory>/Adobe/Adobe LiveCycle ES4/sdk/client-libs/common 
 * 
 * For complete details about the location of these JAR files, 
 * see "Including LiveCycle server library files" in the Programming 
 * with LiveCycle server 
 */ 
import java.util.*; 
import java.io.File; 
import java.io.FileInputStream; 
import com.adobe.idp.Document; 
import com.adobe.idp.dsc.clientsdk.ServiceClientFactory; 
import com.adobe.idp.dsc.clientsdk.ServiceClientFactoryProperties; 
import com.adobe.livecycle.rightsmanagement.client.*; 
import com.adobe.livecycle.rightsmanagement.RMSecureDocumentResult; 
 
public class ProtectDocument { 
 
    public static void main(String[] args) { 
    try 
     {        
        //Set connection properties required to invoke LiveCycle ES                                
        Properties connectionProps = new Properties(); 
        connectionProps.setProperty(ServiceClientFactoryProperties.DSC_DEFAULT_EJB_ENDPOINT, "jnp://localhost:1099"); 
        connectionProps.setProperty(ServiceClientFactoryProperties.DSC_TRANSPORT_PROTOCOL,ServiceClientFactoryProperties.DSC_EJB_PROTOCOL);          
        connectionProps.setProperty(ServiceClientFactoryProperties.DSC_SERVER_TYPE, "JBoss"); 
        connectionProps.setProperty(ServiceClientFactoryProperties.DSC_CREDENTIAL_USERNAME, "administrator"); 
        connectionProps.setProperty(ServiceClientFactoryProperties.DSC_CREDENTIAL_PASSWORD, "password"); 
 
        //Create a ServiceClientFactory instance 
        ServiceClientFactory factory = ServiceClientFactory.createInstance(connectionProps); 
        
        //Create a RightsManagementClient object 
        RightsManagementClient rightsClient = new RightsManagementClient(factory); 
        
        //Reference a PDF document to which a policy is applied 
        FileInputStream is = new FileInputStream("C:\\Adobe\\Loan.pdf"); 
        Document inPDF = new Document(is); 
        
        //Create a Document Manager object 
        DocumentManager  documentManager = rightsClient.getDocumentManager(); 
                
        //Apply a policy to the PDF document 
        RMSecureDocumentResult rmSecureDocument =  documentManager.protectDocument( 
                inPDF, 
                "LoanPDF", 
                "Global Policy Set", 
                "SampleDelete3", 
                null, 
                null, 
                null, 
                true); 
 
        
      //Retrieve the policy-protected PDF document 
        Document protectPDF = rmSecureDocument.getProtectedDoc(); 
 
        
        //Save the policy-protected PDF document 
        File myFile = new File("C:\\Adobe\\PolicyProtectedLoanDoc.pdf"); 
        protectPDF.copyToFile(myFile); 
      } 
    catch (Exception ee) 
     { 
        ee.printStackTrace(); 
     } 
    } 
}