当前位置:   article > 正文

java设置pdf加密_如何使用Java对PDF进行加密,密码保护和设置受限权限

pdf设置安全属性 java

java设置pdf加密

Today we will be looking at the document workhorse that is PDF, and how to programmatically employ various features: encryption, password protection, and setting permissions. For Java users, this would normally be a very time-consuming process. However, this article will be covering a much simpler approach to these tasks, as you will soon see.

今天,我们将研究PDF文档,以及如何以编程方式使用各种功能:加密,密码保护和设置权限。 对于Java用户,这通常是一个非常耗时的过程。 但是,您将很快看到,本文将涵盖一种更简单的方法来完成这些任务。

We start by adding two references. First for Jitpack among our repositories:

我们首先添加两个参考。 在我们的存储库中,Jitpack首先:

<repositories>    <repository>        <id>jitpack.io</id>        <url>https://jitpack.io</url>    </repository></repositories>

Then add our client to dependencies.

然后将我们的客户端添加到依赖项。

<dependencies><dependency>    <groupId>com.github.Cloudmersive</groupId>    <artifactId>Cloudmersive.APIClient.Java</artifactId>    <version>v3.54</version></dependency></dependencies>

And now we can call our function for PDF encryption. Use the parameters to customize your desired permissions, passwords, etc.

现在我们可以调用函数进行PDF加密了。 使用参数自定义所需的权限,密码等。

// Import classes://import com.cloudmersive.client.invoker.ApiClient;//import com.cloudmersive.client.invoker.ApiException;//import com.cloudmersive.client.invoker.Configuration;//import com.cloudmersive.client.invoker.auth.*;//import com.cloudmersive.client.EditPdfApi;ApiClient defaultClient = Configuration.getDefaultApiClient();// Configure API key authorization: ApikeyApiKeyAuth Apikey = (ApiKeyAuth) defaultClient.getAuthentication("Apikey");Apikey.setApiKey("YOUR API KEY");// Uncomment the following line to set a prefix for the API key, e.g. "Token" (defaults to null)//Apikey.setApiKeyPrefix("Token");EditPdfApi apiInstance = new EditPdfApi();String ownerPassword = "ownerPassword_example"; // String | Password of a owner (creator/editor) of the PDF file (required)String userPassword = "userPassword_example"; // String | Password of a user (reader) of the PDF file (optional)File inputFile = new File("/path/to/file.txt"); // File | Input file to perform the operation on.String encryptionKeyLength = "encryptionKeyLength_example"; // String | Possible values are \"128\" (128-bit RC4 encryption) and \"256\" (256-bit AES encryption).  Default is 256.Boolean allowPrinting = true; // Boolean | Set to false to disable printing through DRM.  Default is true.Boolean allowDocumentAssembly = true; // Boolean | Set to false to disable document assembly through DRM.  Default is true.Boolean allowContentExtraction = true; // Boolean | Set to false to disable copying/extracting content out of the PDF through DRM.  Default is true.Boolean allowFormFilling = true; // Boolean | Set to false to disable filling out form fields in the PDF through DRM.  Default is true.Boolean allowEditing = true; // Boolean | Set to false to disable editing in the PDF through DRM (making the PDF read-only).  Default is true.Boolean allowAnnotations = true; // Boolean | Set to false to disable annotations and editing of annotations in the PDF through DRM.  Default is true.Boolean allowDegradedPrinting = true; // Boolean | Set to false to disable degraded printing of the PDF through DRM.  Default is true.try {byte[] result = apiInstance.editPdfSetPermissions(ownerPassword, userPassword, inputFile, encryptionKeyLength, allowPrinting, allowDocumentAssembly, allowContentExtraction, allowFormFilling, allowEditing, allowAnnotations, allowDegradedPrinting);System.out.println(result);} catch (ApiException e) {System.err.println("Exception when calling EditPdfApi#editPdfSetPermissions");e.printStackTrace();}

And you are already done! Simple.

您已经完成了! 简单。

翻译自: https://medium.com/@cloudmersive/how-to-encrypt-password-protect-and-set-restricted-permissions-on-a-pdf-in-java-1eb717b069df

java设置pdf加密

声明:本文内容由网友自发贡献,转载请注明出处:【wpsshop博客】
推荐阅读
相关标签
  

闽ICP备14008679号