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

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加密

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值