当您使用iText 5.5.x签署PDF时,通常会执行类似的操作
// Creating the reader and the stamper PdfReader reader = new PdfReader(SRC); FileStream os = new FileStream(DEST, FileMode.Create); PdfStamper stamper = PdfStamper.CreateSignature(reader, os, '\0'); // Creating the appearance PdfSignatureAppearance appearance = stamper.SignatureAppearance; appearance.Reason = "Test customized appearance"; appearance.Location = "Singularity"; appearance.SetVisibleSignature(new Rectangle(36, 748, 144, 780), 1, "sig"); // Creating the signature IExternalSignature pks = new PrivateKeySignature(parameters, DigestAlgorithms.SHA256); MakeSignature.SignDetached(appearance, pks, chain, null, null, null, 0, CryptoStandard.CADES);
您可以通过在图层模板之后处理图层模板来自由地自定义视觉外观 appearance.SetVisibleSignature 电话,例如像这样:
appearance.SetVisibleSignature
// trigger creation of default layers contents appearance.GetAppearance(); // Customize the layer contents PdfTemplate layer2 = appearance.GetLayer(2); Rectangle rect = appearance.Rect; layer2.SetRGBColorStroke(255, 0, 0); layer2.SetLineWidth(2); layer2.Rectangle(rect.Left, rect.Bottom, rect.Width, rect.Height); layer2.Stroke();
沿着签名外观边框绘制一条红线