I've just thrown together a quick example by adapting one of the other sdk samples. This will take a pdf file, encrypt it, and reader extend it. The input file needs to have no encryption on to begin with.<br /><br />The instructions for compiling and running the samples can be found in the sdkHelp.zip of the LiveCycle ES SDK Help.<br /><br />http://www.adobe.com/support/documentation/en/livecycle/<br /><br />Here goes:<br /><pre><br />/*<br /><br />ADOBE SYSTEMS INCORPORATED<br /><br />Copyright 2007 Adobe Systems Incorporated<br /><br />All Rights Reserved<br /><br /> <br /><br />NOTICE: Adobe permits you to use, modify, and distribute this file in accordance with the <br /><br />terms of the Adobe license agreement accompanying it. If you have received this file from a <br /><br />source other than Adobe, then your use, modification, or distribution of it requires the prior <br /><br />written permission of Adobe.<br /><br />*/<br /><br />package com.test;<br /><br />import com.adobe.idp.Document;<br /><br />import com.adobe.idp.dsc.clientsdk.ServiceClientFactory;<br /><br />import com.adobe.idp.dsc.clientsdk.ServiceClientFactoryProperties;<br /><br />import com.adobe.livecycle.encryption.client.EncryptionServiceClient;<br /><br />import com.adobe.livecycle.encryption.client.PasswordEncryptionOption;<br /><br />import com.adobe.livecycle.encryption.client.PasswordEncryptionOptionSpec;<br /><br />import com.adobe.livecycle.encryption.client.PasswordEncryptionPermission;<br /><br />import com.adobe.livecycle.readerextensions.client.ReaderExtensionsOptionSpec;<br /><br />import com.adobe.livecycle.readerextensions.client.ReaderExtensionsServiceClient;<br /><br />import com.adobe.livecycle.readerextensions.client.UsageRights;<br /><br />import java.io.File;<br /><br />import java.util.List;<br /><br />import java.util.Properties;<br /><br />import java.util.Vector;<br /><br />public class EncryptAndExtend <br /><br />{<br /><br /> private static String _pdf_file_name = null;<br /><br /> <br /><br /> private static String _user_name = null;<br /><br /> private static String _password = null;<br /><br /> private static String _server_url = null;<br /><br /> private static String _server_type = null;<br /><br /> private static String _connection_type = null;<br /><br /> <br /><br /> private static Properties _scf_props = null;<br /><br /> private static EncryptionServiceClient _enc_client = null;<br /><br /> private static ReaderExtensionsServiceClient _lcre_client = null;<br /><br /> private static ServiceClientFactory _scf_factory = null;<br /><br /> <br /><br /> private static void encryptAndExtendSample()<br /><br /> {<br /><br /> final String OUT_FILE_NAME = "enc_ex_sample.pdf";<br /><br /> <br /><br /> File in_pdf_file = new File(_pdf_file_name); <br /><br /> <br /><br /> String path_name = in_pdf_file.getParent(); <br /><br /> String out_file_name = new File(path_name, OUT_FILE_NAME).getAbsolutePath();<br /><br /> Document in_doc = new Document(new File(_pdf_file_name), false);<br /><br /> <br /><br /> // set up the encryption opens, passwords, etc.<br /><br /> PasswordEncryptionOptionSpec doc_spec = new PasswordEncryptionOptionSpec();<br /><br /> doc_spec.setDocumentOpenPassword("open");<br /><br /> doc_spec.setPermissionPassword("master");<br /><br /> doc_spec.setEncryptOption(PasswordEncryptionOption.ALL);<br /><br /> List<PasswordEncryptionPermission> perms = new Vector<PasswordEncryptionPermission>();<br /><br /> perms.add(PasswordEncryptionPermission.PASSWORD_EDIT_ADD);<br /><br /> doc_spec.setPermissionsRequested(perms);<br /><br /> Document enc_doc = null;<br /><br /> try {<br /><br /> //encrypt the document using the spec<br /><br /> enc_doc = _enc_client.encryptPDFUsingPassword(in_doc, doc_spec);<br /><br /> <br /><br /> //set up the reader extensions options<br /><br /> ReaderExtensionsOptionSpec opts = new ReaderExtensionsOptionSpec();<br /><br /> UsageRights rights = new UsageRights();<br /><br /> rights.setEnabledComments(true);<br /><br /> opts.setUsageRights(rights);<br /><br /> <br /><br /> //since we haven't save the file to disk since encrypting it, we<br /><br /> //don't need to call unlock prior to applying usage rights<br /><br /> Document lcre_output = _lcre_client.applyUsageRights(enc_doc, <removed>, <removed>, opts);<br /><br /> <br /><br /> //write the output, done.<br /><br /> lcre_output.copyToFile(new File(out_file_name));<br /><br /> } catch (Exception e) {<br /><br /> e.printStackTrace();<br /><br /> System.exit(0);<br /><br /> }<br /><br /> }<br /><br /> <br /><br /> private static void initializeClientConnections()<br /><br /> {<br /><br /> _scf_factory = ServiceClientFactory.createInstance(_scf_props);<br /><br /> _enc_client = new EncryptionServiceClient(_scf_factory);<br /><br /> _lcre_client = new ReaderExtensionsServiceClient(_scf_factory);<br /><br /> }<br /><br /> <br /><br /> private static void initializeConnectionParameters(String[] args) throws IllegalArgumentException <br /><br /> {<br /><br /> _server_url = args[0];<br /><br /> _user_name = args[1];<br /><br /> _password = args[2];<br /><br /> _server_type = args[3];<br /><br /> _pdf_file_name = args[4];<br /><br /> _connection_type = args.length <= 5 ? "SOAP" : args[5]; <br /><br /> <br /><br /> if( !_connection_type.equalsIgnoreCase("SOAP") && <br /><br /> !_connection_type.equalsIgnoreCase("EJB") )<br /><br /> {<br /><br /> throw new IllegalArgumentException("The 'connection type' parameter may only be 'SOAP' or 'EJB'");<br /><br /> }<br /><br /> }<br /><br /> <br /><br /> private static void initializeSCFProperties()<br /><br /> {<br /><br /> _scf_props = new Properties();<br /><br /> <br /><br /> _scf_props.setProperty( ServiceClientFactoryProperties.DSC_CREDENTIAL_USERNAME, _user_name );<br /><br /> _scf_props.setProperty( ServiceClientFactoryProperties.DSC_CREDENTIAL_PASSWORD, _password );<br /><br /> <br /><br /> if(_connection_type.equalsIgnoreCase("SOAP"))<br /><br /> {<br /><br /> _scf_props.setProperty( ServiceClientFactoryProperties.DSC_SERVER_TYPE, _server_type );<br /><br /> _scf_props.setProperty( ServiceClientFactoryProperties.DSC_DEFAULT_SOAP_ENDPOINT, _server_url );<br /><br /> _scf_props.setProperty( ServiceClientFactoryProperties.DSC_TRANSPORT_PROTOCOL, "SOAP" );<br /><br /> }<br /><br /> else if(_connection_type.equalsIgnoreCase("EJB"))<br /><br /> {<br /><br /> _scf_props.setProperty( ServiceClientFactoryProperties.DSC_SERVER_TYPE, _server_type );<br /><br /> _scf_props.setProperty( ServiceClientFactoryProperties.DSC_DEFAULT_EJB_ENDPOINT, _server_url );<br /><br /> _scf_props.setProperty( ServiceClientFactoryProperties.DSC_TRANSPORT_PROTOCOL, "EJB" );<br /><br /> <br /><br /> // NOTE: these environment parameters should be specified at the command line with -D for JBoss EJB <br /><br /> // Different environment parameters may be necessary for other app servers.<br /><br /> //<br /><br /> _scf_props.setProperty( "java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory" );<br /><br /> _scf_props.setProperty( "java.naming.factory.url.pkgs", "org.jboss.naming:org.jnp.interfaces" );<br /><br /> }<br /><br /> }<br /><br /> <br /><br /> private static void printUsage()<br /><br /> {<br /><br /> System.out.println( "EncryptAndExtend usage:");<br /><br /> System.out.println( "EncryptAndExtend <server url> <user name> <password> <server type> <absolute PDF file name> [connection type]");<br /><br /> System.out.println( " where 'server type' is the type of server (e.g. JBoss), and 'connection type' optionally specifies SOAP or EJB. SOAP is the default");<br /><br /> }<br /><br /> <br /><br /> /**<br /><br /> * @param args<br /><br /> * Expects six arguments in the args array: <br /><br /> * URL, username, password, server type, file path (PDF), and policy name<br /><br /> */<br /><br /> public static void main(String[] args) <br /><br /> {<br /><br /> try<br /><br /> { <br /><br /> // Initialize the connection parameters from our arguments<br /><br /> if(args.length < 5 || args.length > 6)<br /><br /> {<br /><br /> printUsage();<br /><br /> <br /><br /> return;<br /><br /> } <br /><br /> initializeConnectionParameters(args);<br /><br /> initializeSCFProperties();<br /><br /> initializeClientConnections();<br /><br /> encryptAndExtendSample(); <br /><br /> }<br /><br /> catch(IllegalArgumentException e)<br /><br /> {<br /><br /> System.out.println("One or more parameters to the sample was incorrect:");<br /><br /> System.out.println(e.getMessage());<br /><br /> <br /><br /> printUsage();<br /><br /> } <br /><br /> }<br /><br />}<br /></pre>