- #ADOBE PDF SIGNATURE PRO#
- #ADOBE PDF SIGNATURE CODE#
- #ADOBE PDF SIGNATURE PASSWORD#
- #ADOBE PDF SIGNATURE ISO#
PdfSignatureAppearance appearance = stamper.getSignatureAppearance() ĪtVisibleSignature("Signature") ĮxternalDigest digest = new Bounc圜astleDigest() ĮxternalSignature signature = new PrivateKeySignature(pk, DigestAlgorithms.SHA256, "BC") Stamper = PdfStamper.createSignature(reader, os, '\0', null, true) Reader = new PdfReader(baos.toByteArray()) įileOutputStream os = new FileOutputStream("target/test-outputs/test_signed-with-lock-field-2step.pdf") Creating the reader and the stamper for signing STEP 2 - sign the prepared signature field, nothing special PdfFormField field = PdfFormField.createSignature(stamper.getWriter()) įield.put(PdfName.LOCK, stamper.getWriter().addToBody(new PdfSigLockDictionary(LockPermissions.NO_CHANGES_ALLOWED)).getIndirectReference()) įtFlags(PdfAnnotation.FLAGS_PRINT) įtWidget(new Rectangle(150, 250, 300, 401), PdfAnnotation.HIGHLIGHT_INVERT) PdfStamper stamper = new PdfStamper(reader, baos, (char)0, true) Creating the reader and the stamper for adding the fieldīyteArrayOutputStream baos = new ByteArrayOutputStream() STEP 1 - prepare a signature field with locking information I did it in Java (I'm more at home there) but this should not be too difficult to port to C#.
Thus, here a two-step solution first adding an empty signature field with locking information and then signing this field. I tried to do this in one step but, unfortunately, iText in its current state (version 5.4.4) only properly supports lock dictionaries in already existing It should not be too difficult to add a lock dictionary support for fields created on the run while signing, too.
#ADOBE PDF SIGNATURE ISO#
For details read ISO 32000-1, especially section 12.8. The solution is somewhat more difficult: Instead of the DocMDP transform method (used for certification) the FieldMDP transform method has to be used. But as your use case is toĪdd a new signature in a new signature field to an existing PDF which may or may not be signed, If your use case only required signing unsigned PDFs, locking would be easy: You simply would have set CertificationLevel = CERTIFIED_NO_CHANGES_ALLOWED for your PdfSignatureAppearance object.
Is this the problem? Does iTextSharp simply not support what's actually possible? But calling this method together with appending a signature leads to the following DocumentException: "Append mode does not support changing the encryption status." I haven't seen a method that sets permissions but not encryption. I have further investigated the issue and it seems to come from here: The permissions can only be set through the PdfStamper.SetEncryption method, as its 4th parameter. But at least other Acrobat users should see the "intended permissions" correctly.) (I'm aware that my application will still be able to sign the document because it doesn't care for the existing permissions. So how can I achieve the same result as with Acrobat? The latest version has incompatible API changes that I didn't resolve yet.
#ADOBE PDF SIGNATURE CODE#
My code is based on the iSafePDF project (open-source on Codeplex) which is using PdfStamper in some way on an existing document.
#ADOBE PDF SIGNATURE PASSWORD#
Also, I don't really want to use it because a) it's basically useless without a viewer password and b) Acrobat doesn't do it either when locking a document after signing. I'm not using encryption because that is only possible before putting the first signature. I do not set the following permissions (which should be all else):Īnyway, after saving a document like that, I see the following permissions in Acrobat X Pro:
#ADOBE PDF SIGNATURE PRO#
iTextSharp basically also can set the document's permissions, but somehow I can't get it to set the same permissions as Acrobat X Pro does.
ITextSharp can also sign documents, and it can also add further signatures to an already signed document. This seems like a reasonable action to do after a document has been signed for review by multiple entities and finally for release by someone responsible. This changes the document permissions so that Acrobat does not offer signing the document again or modifying annotations or forms. Adobe Acrobat has the option to lock the PDF document after signing it.