使用 itext 签名后锁定文档
签署 pdf 后,我想锁定文档,因此无法添加更多签名,
我尝试像这样添加锁定:
PdfDictionary dic2 = new PdfDictionary();
dic2.put(PdfName.CONTENTS, new PdfString(placeHolder).setHexWriting(true));
dic2.put(PdfName.LOCK, stamper.getWriter()
.addToBody(new PdfSigLockDictionary(LockPermissions.NO_CHANGES_ALLOWED)).getIndirectReference());
pdfAppearance.close(dic2);
但我收到此错误:
java.lang.IllegalArgumentException: The key /Lock didn't reserve space in preClose().
我找不到有关如何的明确示例添加这个锁,我做错了什么?我正在使用 itext 5。
编辑 1: 在预关闭中设置锁定长度,如下所示:
PdfSigLockDictionary dic3 = new PdfSigLockDictionary(LockPermissions.NO_CHANGES_ALLOWED);
HashMap<PdfName, Integer> exc = new HashMap<PdfName, Integer>();
exc.put(PdfName.LOCK, dic3.length()* 2 + 2);
pdfAppearance.preClose(exc);
after signing a pdf, I want to lock the document, so no more signatures can be added,
I'm trying to add the lock like this:
PdfDictionary dic2 = new PdfDictionary();
dic2.put(PdfName.CONTENTS, new PdfString(placeHolder).setHexWriting(true));
dic2.put(PdfName.LOCK, stamper.getWriter()
.addToBody(new PdfSigLockDictionary(LockPermissions.NO_CHANGES_ALLOWED)).getIndirectReference());
pdfAppearance.close(dic2);
but I'm getting this error:
java.lang.IllegalArgumentException: The key /Lock didn't reserve space in preClose().
I can't find a clear example on how to add this lock, what am I doing wrong? I'm using itext 5.
EDIT 1:
setting the LOCK lenght in the preclose like this:
PdfSigLockDictionary dic3 = new PdfSigLockDictionary(LockPermissions.NO_CHANGES_ALLOWED);
HashMap<PdfName, Integer> exc = new HashMap<PdfName, Integer>();
exc.put(PdfName.LOCK, dic3.length()* 2 + 2);
pdfAppearance.preClose(exc);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论