C#如何给PDF添加可见的数字签名

数字签名是作为文档加密的方式之一,在工作中的应用广泛。本文提供了如何使用C#语言来给PDF文档添加数字签名的方法,供参考。

使用工具:Free Spire.PDF for .NET

注意:代码操作前需要先添加引用DLL文件到项目中,并同时添加到命名空间

(本文转载自http://www.cnblogs.com/Yesi/p/6665453.html)

//新建一个PDF文档对象,再添加一个新页面。
PdfDocument doc = new PdfDocument();
doc.Pages.Add();
//加载一个PDF证书           
PdfCertificate cert = new PdfCertificate(@"C:\Users\Administrator\Desktop\gary.pfx", "e-iceblue");

//添加数字签名
var signature = new PdfSignature(doc, doc.Pages[0], cert, "Requestd1");
//设置数字签名的位置
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 = "Le document est certifie";

signature.DateLabel = "Date: ";
signature.Date = DateTime.Now;

signature.ContactInfoLabel = "Contact: ";
signature.ContactInfo = "123456789";

signature.Certificated = false;

signature.ConfigGraphicType = ConfiguerGraphicType.TextSignInformation;

signature.DocumentPermissions = PdfCertificationFlags.ForbidChanges;

//保存文档
doc.SaveToFile("sample.pdf");
//打开文档
System.Diagnostics.Process.Start("sample.pdf");

 效果示例:

(本文完)

猜你喜欢

转载自miaonly.iteye.com/blog/2399061
今日推荐