pdfitextsigningcustomizationstamp

Customize PDFStamper using iTextSharp


I'm using iTextSharp to sign PDFs. When signing, it stamps the document with 4 fields: who signed, when, reason and location. What I meant to do is to add a field below (or above, that doesn't matter) with custom information.

Any Idea?

Here's my code that is generating the stamp:

PdfStamper stp = PdfStamper.CreateSignature(reader, memoryOut, '\0');
        PdfSignatureAppearance sap = stp.SignatureAppearance;

        iTextSharp.text.Rectangle rectangle = new iTextSharp.text.Rectangle(100, 100, 500, 200);

        sap.SetVisibleSignature(rectangle, stp.Reader.NumberOfPages, null);
        sap.SignDate = DateTime.Now;
        sap.SetCrypto(null, chain, null, null);
        sap.Reason = ssReason;
        sap.Contact = ssContact;
        sap.Location = ssLocation;

        sap.Acro6Layers = true;
        //sap.SignatureGraphic = iTextSharp.text.Image.GetInstance(ssImageUrl);
        //sap.SignatureGraphic.ScaleToFit(131, 45);
        sap.Render = PdfSignatureAppearance.SignatureRender.Description;

Solution

  • Several options:

    1. modify one of the PdfTemplates from sap.getLayer(int).

    2. call sap.setLayer2Text() to include your extra information.

    3. Use a graphic. You can wrap a PdfTemplate in an Image, so you can draw anything you want. Then

      sap.Render = PdfSignatureAppearance.SignatureRender.GraphicAndDescription

    4. Hack The Source.