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');
PdfSignatureAppea开发者_如何学Pythonrance 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;
Several options:
modify one of the
PdfTemplate
s fromsap.getLayer(int)
.call
sap.setLayer2Text()
to include your extra information.Use a graphic. You can wrap a
PdfTemplate
in anImage
, so you can draw anything you want. Thensap.Render = PdfSignatureAppearance.SignatureRender.GraphicAndDescription
Hack The Source.
精彩评论