数字签名广泛用于保护PDF文档,可见数字签名在日常生活中是相当重要的。在这篇文章中我将与大家分享如何给PDF文件添加可见的数字签名。
首先我下载了一个由E-iceblue公司开发的免费版的PDF组件-Free Spire.PDF,控件安装好后,再通过下面所提及的路径把Bin文件夹里的Spire.PDF.dll添加为引用。
路径:"...\Spire.pdf-fe\Bin\NET4.0\ Spire.PDF.dll"
接下来我将提供一些代码片段来向大家展示如何添加可见的数字签名:
步骤1:新建一个PDF文档并加载一个PDF证书
//新建一个PDF文档对象,再添加一个新页面。PdfDocument doc = new PdfDocument();doc.Pages.Add();//加载一个PDF证书 PdfCertificate cert = new PdfCertificate(@"C:\Users\Administrator\Desktop\gary.pfx", "e-iceblue");步骤2:添加数字签名并设置数字签名的位置
//添加数字签名var signature = new PdfSignature(doc, doc.Pages[0], cert, "Requestd1");//设置数字签名的位置signature.Bounds = new RectangleF(new PointF(280, 600), new SizeF(260, 90));步骤3:设置显示文本属性
signature.IsTag = true;步骤4:填充数字签名的内容
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;步骤5:设置数字签名的文档权限
signature.DocumentPermissions = PdfCertificationFlags.ForbidChanges;步骤6:将文档以PDF格式保存到文件夹中
//保存文档doc.SaveToFile("sample.pdf");//打开文档System.Diagnostics.Process.Start("sample.pdf");效果图:
以上就是c# 给pdf添加数字签名的步骤的详细内容,更多关于c# pdf添加数字签名的资料请关注其它相关文章!