Reputation: 89
I have written a code to lock fields in the document using iText7, the fields are locked in the final document but when left signature panel is opened in Adobe, there is no information regarding field locking is present there.
My code snippet is as follows:
PdfSigFieldLock pdfSigFieldLock = new PdfSigFieldLock();
pdfSigFieldLock.SetDocumentPermissions(PdfSigFieldLock.LockPermissions.NO_CHANGES_ALLOWED);
string[] fieldToLock = new string[]{ fieldName };
pdfSigFieldLock.SetFieldLock(PdfSigFieldLock.LockAction.ALL, fieldToLock);
pdfSigner.SetFieldLockDict(pdfSigFieldLock);
Document fields are locked but no information regarding document fields locking is shown in signature panel. (expected result shown in image)
Upvotes: 0
Views: 648
Reputation: 89
The above scenario can be achieved by manually add values to the PdfSigFieldLock Dictionary. Here is the code snippet:
PdfDictionary lockDictionary = new PdfDictionary();
lockDictionary.Put(PdfName.Action, new PdfName("All"));
lockDictionary.Put(PdfName.P, new PdfNumber(1));
PdfSigFieldLock pdfSigFieldLock = new PdfSigFieldLock(lockDictionary);
pdfSigner.SetFieldLockDict(pdfSigFieldLock);
Upvotes: 1
Reputation: 96064
Please try and remove the Fields from the Lock dictionary:
PdfSigFieldLock pdfSigFieldLock = new PdfSigFieldLock();
pdfSigFieldLock.SetDocumentPermissions(PdfSigFieldLock.LockPermissions.NO_CHANGES_ALLOWED);
string[] fieldToLock = new string[]{ fieldName };
pdfSigFieldLock.SetFieldLock(PdfSigFieldLock.LockAction.ALL, fieldToLock);
pdfSigFieldLock.GetPdfObject().Remove(PdfName.Fields); // <<<<
pdfSigner.SetFieldLockDict(pdfSigFieldLock);
In my tests I did get the desired output with that change.
Some backgrounds:
That Fields entry is specified as Required if the value of Action is Include or Exclude (ISO 32000-1, Table 233 – Entries in a signature field lock dictionary). In case of the action All as in your case, therefore, it is neither required nor optional. Furthermore, it does not make sense in that case either because all fields shall be locked anyways. Adobe Reader, therefore, apparently considers a signature field lock dictionary with a Fields entry for an All action incorrect. (Well, probably it would accept that entry if all field names of the document are contained, I did not check all possible contents...)
The iText 7 class PdfSigFieldLock
unfortunately currently automatically creates such a Fields, so you have to remove it..
Upvotes: 1