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 applyUsageRights
Java 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)
Retrieve usage rights applied to a policy-protected PDF document.
You can use the getDocumentUsageRights
Java 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)
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();