且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

将pdf与数字签名与itext 5.4.0或最大值合并会产生错误

更新时间:2023-02-12 21:19:42

你的推理中有两个错误。一个可以修复,一个不是技术错误,但是一个无法修复的推理错误。

There are two errors in your reasoning. One that can be fixed, one that is a not a technical error, but a reasoning error that can't be fixed.

技术错误:
在关闭文档之前关闭阅读器。那太早了。 PdfCopy 文档需要在 document.close()$ c时访问阅读器$ c>被调用。你已经关闭了循环中的 reader 实例,然后 java.lang.IllegalStateException 通知你资源是已经关闭

The technical error: You close the reader before you close the document. That's too early. PdfCopy and Document need access to the reader when document.close() is invoked. You've already closed the reader instance in the loop, hance the java.lang.IllegalStateException informing you that the resource is Already closed.

您的假设存在的问题:数字签名是一种保证完整性的方法文献。当有人签署一份5页的文件时,该人希望确保他签署了这5页,而不是更多,而不是更少。您现在要添加页面。这将永远打破签名!

The problem with your assumption: Digital signatures are a way to guarantee the integrity of a document. When somebody signs a document with 5 pages, that person wants to make sure he signed those 5 pages, not more, not less. You are now going to add pages. That will always break the signature!

如果要组合经过数字签名的PDF文档:
- 禁止到汇总这些文件:如果你这样做,签名将会消失或破裂。
- 您唯一的选择是将文档合并到便携式集合中。在这种情况下,主PDF用作存储单独PDF的包或产品组合。这样的PDF保持不变(如果不是:签名中断)。

If you want to combine PDF documents that are digitally signed: - it is forbidden to assemble those documents: if you do, the signatures will either disappear or break. - your only option is to combine the documents in a portable collection. In this case, a master PDF acts as a package or portfolio to store the separate PDFs. The PDFs as such are kept intact (if not: the signature shall break).