您必须熟悉文档安全、读者扩展和Java编程语言等概念,才能对受文档安全策略保护的PDF文档进行阅读器扩展。
您可以使用文档安全性将特定PDF文档的访问限制为仅授权用户。 您还可以确定收件人如何使用受保护的文档。 例如,您可以指定收件人是否可以打印、复制或编辑受安全策略保护的文档的文本。 要了解有关文档安全性的更多信息,请参阅关于文档安全。
您可以使用Reader扩展在Adobe PDF文档中通过Acrobat Reader启用交互功能。 这些交互功能通常仅通过Adobe Acrobat Professional和Standard提供。 要了解Reader扩展可启用的交互式功能,请参阅Adobe Experience Manager Forms DocAssurance服务。
您可以使用便携式保护库对文档应用策略,而无需通过网络传输文档。 只有安全凭据和保护策略详细信息才能通过网络传输。 实际文档永远不会离开客户端,并且保护策略会在客户端本地应用。
受策略保护的文档是加密文档。 您不能使用标准的Reader扩展API来应用、删除和检索受策略保护的PDF文档的使用权限。 只有可移植保护库的Reader扩展服务提供API来应用、删除和检索文档安全策略保护的PDF文档的使用权限。
Reader扩展服务可将使用权限添加到受策略保护的PDF文档,从而激活在使用Adobe AcrobatReader打开PDF文档时通常不可用的功能。 它还具有用于删除和检索受策略保护文档的使用权限的API。
Reader扩展服务完全支持基于PDF standard 1.6及更高版本的PDF文档。 除了Acrobat Reader之外,第三方用户使用受策略保护的PDF文档时不需要任何其他软件或插件。
您可以使用Reader扩展服务完成以下任务:
您可以使用applyUsageRights
Java API将使用权限应用于受策略保护的PDF文档。 使用权限与Acrobat中默认提供但Adobe Reader中不提供的功能有关,例如向表单添加注释或填写表单字段并保存表单的功能。 对其应用了使用权限的PDF文档称为启用了权限的文档。 在Adobe Reader中打开启用了权限的文档的用户可以执行为该特定文档启用的操作。
语法: InputStream applyUsageRights(InputStream inputFile, File certFile, String credentialPassword, UsageRights usageRights)
参数 |
描述 |
inputFile |
指定表示要应用使用权限的PDF文档的InputStream。 您可以使用LiveCycleRights Management或AEM Forms文档安全保护文档。 |
certFile |
指定表示.jks文件的文件对象。 .jks文件是KeyStore文件。 它指向授予使用权限的证书。 |
credentialPassword |
指定密钥库的密码。 |
usageRights |
指定类型UsageRights的对象。 usageRights对象表示可应用于受策略保护的PDF文档的单个权限。 |
您可以使用getDocumentUsageRights
Java API检索应用于受策略保护的PDF文档的Reader扩展使用权限。 通过检索有关使用权限的信息,您可以了解受策略保护的PDF文档已启用的读者扩展功能。
语法: public GetUsageRightsResult getDocumentUsageRights(InputStream inDoc)
参数 |
描述 |
inDoc |
指定表示要从中检索使用权限的PDF文档的InputStream。 您可以使用LiveCycleRights Management或AEM Forms文档安全保护文档。 |
//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();
您可以使用removeUsageRights
Java API从受策略保护的文档中删除使用权限。 要对文档执行其他AEM Forms操作,必须从受策略保护的PDF文档中删除使用权限。 例如,在设置使用权限之前,您必须对PDF文档进行数字签名(或验证)。 因此,如果要对受策略保护的文档执行操作,则必须从PDF文档中删除使用权限,执行其他操作(如对文档进行数字签名),然后对文档重新应用使用权限。
语法: InputStream removeUsageRights(InputStream inputFile)
参数 |
描述 |
inputFile |
指定表示要从中删除使用 权限的PDF文档的InputStream。 您可以使用LiveCycleRights Management或AEM Forms文档安全保护文档。 |
//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();