private void BuildSignatureAppearance(PdfSigner signer, Signature signing) { // Creating the appearance PdfSignatureAppearance appearance = signer.GetSignatureAppearance(); appearance.SetReason(signing.SignReason); appearance.SetContact(signing.SignContact); appearance.SetLocation(signing.SignLocation); var arial = PdfFontFactory.CreateFont(Environment.GetEnvironmentVariable("WINDIR") + "\\Fonts\\Arial.ttf", PdfName.WinAnsiEncoding.GetValue(), true); appearance.SetLayer2Font(arial); if (!signing.AllowMultiSigning) { signer.SetCertificationLevel(PdfSigner.CERTIFIED_FORM_FILLING_AND_ANNOTATIONS); appearance.SetCertificate(signer.GetSignatureAppearance().GetCertificate()); } if (signing.DisplaySignatureInDocument) { var signPage = SignPageNr(signer, signing); var left = signing.LeftX; var bottom = signing.LeftY; var width = signing.RightX - left; var height = signing.RightY - bottom; var rect = new Rectangle(left, bottom, width, height); appearance.SetPageRect(rect); appearance.SetPageNumber(signPage); } }
public void Sign1(String src, String name, String dest, X509Certificate[] chain, ICipherParameters pk, String digestAlgorithm, PdfSigner.CryptoStandard subfilter, String reason, String location) { PdfReader reader = new PdfReader(src); PdfSigner signer = new PdfSigner(reader, new FileStream(dest, FileMode.Create), new StampingProperties()); // Create the signature appearance PdfSignatureAppearance appearance = signer.GetSignatureAppearance(); appearance .SetReason(reason) .SetLocation(location); // This name corresponds to the name of the field that already exists in the document. signer.SetFieldName(name); // Set the custom text and a custom font appearance.SetLayer2Text("This document was signed by Bruno Specimen"); appearance.SetLayer2Font(PdfFontFactory.CreateFont(StandardFonts.TIMES_ROMAN)); IExternalSignature pks = new PrivateKeySignature(pk, digestAlgorithm); // Sign the document using the detached mode, CMS or CAdES equivalent. signer.SignDetached(pks, chain, null, null, null, 0, subfilter); }