Reader extending document security policy-protected PDF documents

The policy-protected documents are encrypted documents. You cannot use standard reader-extension APIs to apply, remove, and retrieve usage rights of a policy-protected PDF documents. Only Reader Extensions service of Portable Protection Library provides APIs to apply, remove, and retrieve usage rights of a document security policy-protected PDF documents.

Reader Extensions service

The reader extension service adds usage rights to a policy-protected PDF document, activating features that are not normaly available when a PDF document is opened using Adobe Acrobat Reader. It also has APIs to remove and retrieve usage rights of a policy-protected document.

The Reader Extensions service fully supports PDF documents based on PDF standard 1.6 and later. Apart from Acrobat Reader, third-party users do not require any additional software or plug-ins to use the policy-protected PDF documents.

You can accomplish the following tasks with the Reader Extensions service:

  • Apply usage rights to a policy-protected PDF document.
  • Remove usage rights of a policy-protected PDF document.
  • Retrieve usage rights applied to a policy-protected PDF document.

Apply usage rights to a document security policy-protected PDF document

You can use the applyUsageRightsJava API to apply usage rights to policy-protected PDF documents. Usage rights pertain to functionality that is available by default in Acrobat but not in Adobe Reader, such as the ability to add comments to a form or to fill in form fields and save the form. PDF documents that have usage rights applied to them are called rights-enabled documents. A user who opens a rights-enabled document in Adobe Reader can perform operations that are enabled for that specific document.

Syntax: InputStream applyUsageRights(InputStream inputFile, File certFile, String credentialPassword, UsageRights usageRights)

ParameterDescription
inputFileSpecify InputStream that represents the PDF document to which usage rights are to be applied. You can use LiveCycle Rights Management or AEM Forms document security protected documents.
certFileSpecify File object that represents a .jks file. The .jks file is a keystore file. It points to a certificate that grants usage rights.
credentialPasswordSpecify password of the keystore.
usageRightsSpecifies an object of type UsageRights. The usageRights object represents individual rights that can be applied to a policy-protected PDF document.

Retrieve usage rights applied to a policy-protected PDF document.  

You can use the getDocumentUsageRightsJava API to retrieve the reader extension usage rights applied to a policy-protected PDF document. By retrieving information about usage rights, you can learn about the features reader extension has enabled for the policy-protected PDF document.

Syntax: public GetUsageRightsResult getDocumentUsageRights(InputStream inDoc)

ParameterDescription
inDocSpecify InputStream that represents the PDF document from which usage rights are to be retrieved. You can use LiveCycle Rights Management or AEM Forms document security protected documents.

Code Sample

//Create a ServiceClientFactory instance
ServiceClientFactory factory = ServiceClientFactory.createInstance(connectionProps);
//Create a RightsManagementClient object
RightsManagementClient2 rmClient2= new RightsManagementClient2(factory);

String inputFileName = "C:\\Sample\\protected.pdf"; //Input file can be RM protected or unprotected pdf file
File certFile = new File("C:\\Sample\\cert.jks"); //RE certificate file
String password = "password"; //password for RE certificate
UsageRights usageRights = getUsageRights(true,true,false,false,true,true,false,false,false,false,true);

//RE rights to be applied on the file : FormFillIn, FormDataImportExport, SubmitStandalone, OnlineForms, DynamicFormField, DynamicFormPages, BarcodeDecoding, DigitalSignatures, Comments, CommentsOnline, EmbeddedFiles

InputStream inputFileStream = new FileInputStream(inputFileName);
InputStream output = rmClient2.getRightsManagementReaderExtensionService().applyUsageRights(inputFileStream, certFile, credentialPassword, rights);

String outputFileName = "C:\\Sample\\ReAdded.pdf";
//Save the PDF document
File myFile = new File(outputFileName);
FileOutputStream outputStream = new FileOutputStream(myFile);

int read = 0;
byte[] bytes = new byte[1024];

while ((read = output.read(bytes)) != -1) {

    outputStream.write(bytes, 0, read);
}

System.out.println("UsageRights applied successfully to the document. ");
 outputStream.close();
inputFileStream.close();

//Get Usage Rights for the output pdf document
InputStream fileWithRe = new FileInputStream(myFile);

GetUsageRightsResult usageRights = rmClient2.getRightsManagementReaderExtensionService().getDocumentUsageRights(fileWithRe);

UsageRights rights = usageRights.getRights();
String right1 = rights1.toString();
System.out.println("RE rights for the file are :\n"+right1);
 fileWithRe.close();

Remove usage rights of a policy-protected PDF document

You can use the removeUsageRightsJava API to remove usage rights from a policy-protected document. Removing usage rights from a policy-protected PDF document is necessary to perform other AEM Forms operations on the document. For example, you must digitally sign (or certify) a PDF document before you set usage rights. Therefore, if you want to perform operations on a policy-protected document, you must remove usage rights from the PDF document, perform the other operations, such as digitally signing the document, and then re-apply usage rights to the document.

Syntax: InputStream removeUsageRights(InputStream inputFile)

ParameterDescription
inputFileSpecify InputStream that represents the PDF document from which usage
rights are to be removed. You can use LiveCycle Rights Management or AEM Forms document security protected documents.

Code Sample

//Create a ServiceClientFactory instance
ServiceClientFactory factory = ServiceClientFactory.createInstance(connectionProps);
//Create a RightsManagementClient object
RightsManagementClient2 rmClient2= new RightsManagementClient2(factory);

String inputFileName = "C:\\Sample\\fileWithRe.pdf"; //Input file can be RM protected or unprotected pdf file
InputStream inputFileStream = new FileInputStream(inputFileName);

InputStream fileStream = rmClient2.getRightsManagementReaderExtensionService().removeUsageRights(inputFileStream);

String outputFileName = "C:\\Sample\\ReRemoveded.pdf";
//Save the PDF document
File myFile = new File(outputFileName);
FileOutputStream outputStream = new FileOutputStream(myFile);

int read = 0;
byte[] bytes = new byte[1024];

while ((read = fileStream.read(bytes)) != -1) {

    outputStream.write(bytes, 0, read);
}
System.out.println("RE rights removed successfully from the document.");
outputStream.close();
inputFileStream.close();

Experience Manager


Espressos & Experience Manager: AEM Forms

Espressos & Experience Manager

Thursday, Mar 6, 7:00 PM UTC

Join Adobe's AEM product team as they highlight AEM Forms' latest innovations, including: the new Gen AI Assistant, Unified Composition with AEM Sites, and new ways to deploy forms through conversations.

Register

Connect with Experience League at Summit!

Get front-row access to top sessions, hands-on activities, and networking—wherever you are!

Learn more