认证和签名后锁定PDF文件 [英] Locking a PDF file after certification and signing

查看:333
本文介绍了认证和签名后锁定PDF文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试找到一种方法来使用 iText 锁定经过签名和认证的PDF以进行修改.像Abode Reader DC这样的查看器告诉我文档没有打开以进行这样的修改

I'm trying to find a way to lock a signed and certified PDF for modification using iText in a way that viewers like Abode Reader DC tell me the document is not open for modification like this

(如果我使用Adobe对文档进行签名,可以使用PDF版本1.7和iText版本7.1.6.

(which I can do if I sign the document using Adobe) using PDF version 1.7 and iText version 7.1.6.

但是,当我认证并签署pdf时,最终得到的是:

When I certify and sign my pdf however, I end up with this:

在此过程中,首先用证明签名对PDF进行签名,并将证明级别设置为填充PdfSigner.CERTIFIED_FORM_FILLING.

During a process, this PDF is first signed with a certification signature with the certification level set to form filling PdfSigner.CERTIFIED_FORM_FILLING.

此后,PDF将由任意数量的人进行数字签名.

After that the PDF is to be digitally signed by any number of people.

我尝试在签名后放置认证签名并将认证级别设置为PdfSigner.CERTIFIED_NO_CHANGES.这会破坏除认证签名以外的所有签名.

I've tried placing the certification signature and setting the certification level to PdfSigner.CERTIFIED_NO_CHANGES after signing. This breaks all signatures other than the certification signature.

我也尝试过使用密码锁定"文件,但这也没有达到预期的效果.

I've also tried to 'lock' the file with a password, but this also didn't have the desired effect.

在使用iText库放置了最后一个签名之后,是否可以通过任何方式锁定pdf文件,以便在签名和验证后显示第一条消息?

Is there any way to lock a pdf file after the last signature has been placed using the iText library so that the first message shows after signing and certifying?

推荐答案

白皮书仍然是与iText签名相关的所有内容的良好来源.所包含的Java示例代码适用于iText 5.5.x(实际上是5.3.x至5.5.x),但是您可以在

The white paper Digital Signatures for PDF documents by Bruno Lowagie still is a good source for everything related to signing with iText. The contained Java example code is for iText 5.5.x (actually 5.3.x through 5.5.x) but you can find the port to iText 7 in the itext/i7js-signatures github repository.

白皮书在第2.5.5节中讨论了在签名后锁定字段和文档,其中包含一个示例,其中几个签名依次锁定了表单中越来越多的字段,最后一个签名也锁定了表单中的字段.文档,将其从证明者已指定允许该文档的表单填写和签名.不允许其他更改." 证明者已指定不允许对此文档进行任何更改."根据这个问题的需要.

In section 2.5.5 the white paper discusses Locking fields and documents after signing, it contains an example in which several signatures successively lock more and more fields of a form and the final one also locks the document, switching it from "The certifier has specified that Form Fill-in and Signing is allowed for this document. No other changes are permitted." to "The certifier has specified that no changes are allowed to be made to this document." as desired in this question.

示例代码可用

The example code is available here for iText 5.x, and here is the port to iText 7.

不幸的是,iText 7端口的当前代码中存在一个小错误,该错误会导致步骤4的结果(锁定整个文档的签名)导致该签名面板出现:

Unfortunately there is a small bug in the current code of the iText 7 port which causes the result of step 4, the signing that locks down the whole document, to result in this signature panel appearance:

(黄色三角形在那里是因为我不信任测试证书,但红色圆圈和错误文本不应该在那里.)

(The yellow triangles are there because I don't trust the test certificates but the red circle and the error text shouldn't be there.)

这很容易解决,尽管原始示例当前准备的最终签名字段是这样的

This can be fixed easily, though, the original example currently prepares the final signature field like this

lock = new PdfSigFieldLock().setDocumentPermissions(PdfSigFieldLock.LockPermissions.NO_CHANGES_ALLOWED);
table.addCell(createSignatureFieldCell("sig4", lock));

(很遗憾,它忘记了在签名字段锁定字典中设置必需的 Action 条目.您可以将其添加到这样的代码中:

which unfortunately forgets to set the required Action entry in the signature field lock dictionary. You can add that to the code like this:

lock = new PdfSigFieldLock().setFieldLock(PdfSigFieldLock.LockAction.ALL).setDocumentPermissions(PdfSigFieldLock.LockPermissions.NO_CHANGES_ALLOWED);
table.addCell(createSignatureFieldCell("sig4", lock));

现在,签名面板如下所示:

Now the signature panel looks like this:

(如上所述,黄色三角形在那里,因为我不信任测试证书.)

(As mentioned above the yellow triangles are there because I don't trust the test certificates.)

此外,现在可以根据需要声明所有签名的签名属性

Furthermore, as desired the signature properties of all signatures now claim

这篇关于认证和签名后锁定PDF文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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