Digital signature is one of the ways of document encryption, which is widely used in work. This article provides how to use C# language to add digital signature to PDF documents for reference.
Tools used: Free Spire.PDF for .NET
Note: Before code operation, you need to add the reference DLL file to the project and add it to the namespace at the same time
(This article is reproduced from http://www.cnblogs.com/Yesi/p/6665453.html)
//Create a new PDF document object and add a new page. PdfDocument doc = new PdfDocument(); doc.Pages.Add(); //Load a PDF certificate PdfCertificate cert = new PdfCertificate(@"C:\Users\Administrator\Desktop\gary.pfx", "e-iceblue"); //add digital signature var signature = new PdfSignature(doc, doc.Pages[0], cert, "Requestd1"); //Set the location of the digital signature signature.Bounds = new RectangleF(new PointF(280, 600), new SizeF(260, 90)); signature.IsTag = true; signature.DigitalSignerLable = "Digitally signed by"; signature.DigitalSigner = "Gary for Test"; signature.DistinguishedName = "DN:"; signature.LocationInfoLabel = "Location:"; signature.LocationInfo = "London"; signature.ReasonLabel = "Reason: "; signature.Reason = "The document is certified"; signature.DateLabel = "Date: "; signature.Date = DateTime.Now; signature.ContactInfoLabel = "Contact: "; signature.ContactInfo = "123456789"; signature.Certificated = false; signature.ConfigGraphicType = ConfiguerGraphicType.TextSignInformation; signature.DocumentPermissions = PdfCertificationFlags.ForbidChanges; // save the document doc.SaveToFile("sample.pdf"); // open the document System.Diagnostics.Process.Start("sample.pdf");
Example of effect:
(End of this article)