public void Sign(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); // Get the background layer and draw a gray rectangle as a background. PdfFormXObject n0 = appearance.GetLayer0(); float x = n0.GetBBox().ToRectangle().GetLeft(); float y = n0.GetBBox().ToRectangle().GetBottom(); float width = n0.GetBBox().ToRectangle().GetWidth(); float height = n0.GetBBox().ToRectangle().GetHeight(); PdfCanvas canvas = new PdfCanvas(n0, signer.GetDocument()); canvas.SetFillColor(ColorConstants.LIGHT_GRAY); canvas.Rectangle(x, y, width, height); canvas.Fill(); // Set the signature information on layer 2 PdfFormXObject n2 = appearance.GetLayer2(); Paragraph p = new Paragraph("This document was signed by Bruno Specimen."); new Canvas(n2, signer.GetDocument()).Add(p); 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); }