'lock document after sign with itext
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);
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|