开发者

Customize PDFStamper using iTextSharp

开发者 https://www.devze.com 2023-02-09 05:55 出处:网络
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 matte

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:

  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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号