Create Visible Digital Signature in PDF in C#

Digital Signature is widely used to protect the PDF files and it is so important that we always try our best to improve our Spire.PDF better and better. Besides the previous method of creating digital signature in PDF, Spire.PDF now supports to create visible digital signature in PDF with C# code.

Make sure Spire.PDF for .NET (version 2.9 or above) has been installed correctly. Add Spire.PDF.dll as reference in the downloaded Bin folder through the below path: "...\Spire.PDF\Bin\NET4.0\ Spire.PDF.dll".

//load a pdf document
PdfDocument doc = new PdfDocument();

//load the certificate
PdfCertificate cert = new PdfCertificate(@"C:\Users\Administrator\Desktop\gary.pfx", "e-iceblue");

//initialize a PdfSignature instance
PdfSignature signature = new PdfSignature(doc, doc.Pages[0], cert, "Signature1");

//set the signature location
signature.Bounds = new RectangleF(new PointF(200, 200), new SizeF(200, 90));

//set the image of signature
signature.SignImageSource = PdfImage.FromFile(@"C:\Users\Administrator\Desktop\E-iceblueLogo.png");

//set the content of signature
signature.GraphicsMode = GraphicMode.SignImageAndSignDetail;
signature.NameLabel = "Signer:";
signature.Name = "Gary";
signature.ContactInfoLabel = "ContactInfo:";
signature.ContactInfo = signature.Certificate.GetNameInfo(System.Security.Cryptography.X509Certificates.X509NameType.SimpleName, true);
signature.DistinguishedNameLabel = "DN: ";
signature.DistinguishedName = signature.Certificate.IssuerName.Name;
signature.LocationInfoLabel = "Location:";
signature.LocationInfo = "Chengdu";
signature.ReasonLabel = "Reason: ";
signature.Reason = "Le document est certifie";
signature.DateLabel = "Date:";
signature.Date = DateTime.Now;
signature.DocumentPermissions = PdfCertificationFlags.AllowFormFill | PdfCertificationFlags.ForbidChanges;
signature.Certificated = true;

//set fonts
signature.SignDetailsFont = new PdfFont(PdfFontFamily.TimesRoman, 10f);
signature.SignNameFont = new PdfFont(PdfFontFamily.Courier, 15);

//set the sign image layout mode
signature.SignImageLayout = SignImageLayout.None;

//save the file

Create visible digital signature