PdfWriter.ALLOW_ASSEMBLY不会更改“文档程序集"的值.在PDF文档中 [英] PdfWriter.ALLOW_ASSEMBLY does not change the value for "Document Assembly" in the PDF document

查看:91
本文介绍了PdfWriter.ALLOW_ASSEMBLY不会更改“文档程序集"的值.在PDF文档中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用以下代码:

  PdfReader reader = new PdfReader("Input.pdf");PdfStamper压模=新的PdfStamper(阅读器,新的FileOutputStream("Output.pdf"));stamper.setEncryption("password" .getBytes(),"password1" .getBytes,PdfWriter.ALLOW_ASSEMBLY,PdfWriter.STANDARD_ENCRYPTION_128); 

属性 PdfWriter.ALLOW_ASSEMBLY 不会更改文档 Assembly 的值,并且在输出pdf后仍显示为不允许" .已创建.

解决方案

什么加密权限适用于

首先,请注意,在上下文中使用加密授予的权限永远不会比使用未加密文档导致用户执行更多,这些权限仅决定多少< less 允许普通文档用户(即使用用户密码打开PDF的人)与文档所有者(即使用所有者密码打开PDF的人)进行比较.打开未加密的文档时,始终假定拥有完全所有者权限.

因此,在甚至不允许文档所有者进行某些操作的PDF查看器中,在加密期间设置匹配的 ALLOW _ * 标志不会突然使查看器允许某些用户使用这些操作./p>

在当前示例中就是这种情况,Adobe Reader不允许在未加密文档或使用所有者密码打开的文档上进行文档组装.因此,Adobe Reader也不允许在使用 ALLOW_ASSEMBLY 加密的文档中进行文档组装.

文档限制摘要显示的内容

Adob​​e Reader和Adobe Acrobat中文档属性"的安全性"选项卡上的文档限制摘要"不仅反映了加密过程中文档集的权限状态.相反,它们的确是基于大量输入的摘要,但并非全部取决于文档本身:

  • 程序变体默认允许的操作;
  • 通过文档中的使用权签名允许的
  • 其他操作;和
  • 由加密期间未提供的权限引起的限制.

例如在Adobe Reader中,您的文档显示了所有者和用户的以下摘要限制:

在Adobe Acrobat中,您的文档显示了所有者和用户的以下摘要限制:

因此,默认情况下,Adobe Reader不允许文档组装或页面提取.因此,即使 ALLOW_ASSEMBLY ,也不允许以用户身份打开您的文档.

另一方面,默认情况下,Adobe Acrobat允许所有操作.因此,由于 ALLOW_ASSEMBLY ,它确实允许以用户身份打开您的文档的文档组装.

启用阅读器的PDF

如上所述,可以通过使用权限签名来允许超出默认情况下所讨论程序变体所允许的某些操作.很明显,Adobe Reader仅接受由Adobe为此授权的特殊私钥创建的使用权签名.

例如具有足够的Adobe Acrobat版本,您可以使用Adobe Reader中的菜单项扩展功能"来使用它来创建这样的使用权签名,其他Adobe程序也可以用来设置其他使用权.

I am using the following code:

PdfReader reader = new PdfReader("Input.pdf");
PdfStamper stamper = new PdfStamper(reader, new FileOutputStream("Output.pdf"));

stamper.setEncryption("password".getBytes(), "password1".getBytes, PdfWriter.ALLOW_ASSEMBLY, PdfWriter.STANDARD_ENCRYPTION_128);

The property PdfWriter.ALLOW_ASSEMBLY does not change the value of Document Assembly and it still shows as "Not allowed" after output pdf is created.

解决方案

What encryption permissions are for

First of all, please be aware that permissions given in context with encryption never cause the user to be able to do more than he could do with the unencrypted document, these permissions merely decide how much less a regular document user (i.e. a person opening the PDF with the user password) is allowed to do compared with the document owner (i.e. a person opening the PDF with the owner password). When opening an unencrypted document, always the full owner permissions are assumed.

Thus, in a PDF viewer that does not allow certain operations even to a document owner, setting the matching ALLOW_* flags during encryption does not suddenly make the viewer allow those operations to some user.

This is the case in the example at hand, the Adobe Reader does not allow document assembly on an unencrypted document or a document opened with the owner password. Thus, Adobe Reader doesn't allow document assembly in documents encrypted with ALLOW_ASSEMBLY, either.

What the Document Restrictions Summary shows

The Document Restrictions Summary on the Security tab of the Document Properties in Adobe Reader and Adobe Acrobat don't merely reflect the state of the permissions of the document set during encryption. Instead they are indeed a summary based on numerous inputs not all of which depend on the document itself:

  • the operations the program variant allows by default;
  • additional operations allowed via a usage rights signature in the document; and
  • restrictions introduced by permissions not given during encryption.

E.g. in Adobe Reader your document shows these summarized restrictions for owner and user:

In Adobe Acrobat your document shows these summarized restrictions for owner and user:

Thus, Adobe Reader by default does not allow Document Assembly or Page Extraction. So it does not allow them for your document opened as user, either, in spite of ALLOW_ASSEMBLY.

Adobe Acrobat, on the other hand, by default allows everything. So it does allow Document Assembly fr your document opened as user due to the ALLOW_ASSEMBLY.

Reader-enabled PDFs

As mentioned above, some operations in excess of the operations allowed by the program variant in question by default, can be allowed by means of a usage rights signature. Adobe Reader obviously only accepts usage rights signatures created by special private keys authorized for this by Adobe.

If you e.g. have a sufficient Adobe Acrobat version, you can use it to create such a usage rights signature using the menu item Extend Features in Adobe Reader, other Adobe programs can be used to set other usage rights.

这篇关于PdfWriter.ALLOW_ASSEMBLY不会更改“文档程序集"的值.在PDF文档中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆