c# 给pdf添加数字签名的步骤
作者:E-iceblue 时间:2022-04-05 17:58:01
数字签名广泛用于保护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");
效果图:
来源:https://www.cnblogs.com/Yesi/p/6665453.html
标签:c#,pdf,数字签名
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Android 5秒学会使用手势解锁功能
2023-07-11 13:48:32
![](https://img.aspxhome.com/file/2023/1/83511_0s.gif)
IDEA 2020.1 搜索不到Chinese (Simplified) Language Pack EAP,无法安装的问题
2023-11-10 23:54:01
![](https://img.aspxhome.com/file/2023/6/59316_0s.jpg)
C++实现LeetCode(2.两个数字相加)
2023-06-23 16:51:11
springboot中bean的加载顺序问题
2022-01-04 19:55:57
![](https://img.aspxhome.com/file/2023/0/62510_0s.png)
Java StringBuffer与StringBuilder有什么区别
2022-12-15 22:35:12
SpringBoot整合java诊断工具Arthas解读
2023-08-07 10:39:03
![](https://img.aspxhome.com/file/2023/0/69920_0s.png)
java中javaBean与Bean的深入理解
2021-11-27 13:19:11
MyBatis Generator 自定义生成注释的方法
2023-02-24 12:37:23
![](https://img.aspxhome.com/file/2023/1/64031_0s.png)
SpringBoot 集成 activiti的示例代码
2023-01-22 10:22:03
![](https://img.aspxhome.com/file/2023/8/62238_0s.png)
Swagger注解-@ApiModel和@ApiModelProperty的用法
2023-02-05 23:57:48
Java中的zookeeper常用命令详解
2022-12-07 05:46:35
![](https://img.aspxhome.com/file/2023/2/62752_0s.png)
详解Java如何进行Base64的编码(Encode)与解码(Decode)
2023-01-31 18:53:34
Spring实战之属性覆盖占位符配置器用法示例
2023-02-02 00:05:30
![](https://img.aspxhome.com/file/2023/2/66522_0s.png)
Java动态代理分析及理解
2021-10-21 14:59:58
计算机编程语言发展史
2022-10-07 21:28:49
![](https://img.aspxhome.com/file/2023/7/69947_0s.png)
SpringBoot2使用JTA组件实现基于JdbcTemplate多数据源事务管理(亲测好用)
2021-10-12 06:36:09
![](https://img.aspxhome.com/file/2023/4/66964_0s.jpg)
Spring Boot应用程序同时支持HTTP和HTTPS协议的实现方法
2022-01-10 16:50:43
![](https://img.aspxhome.com/file/2023/2/61952_0s.jpg)
JAVA内存模型(JMM)详解
2023-11-23 16:54:32
![](https://img.aspxhome.com/file/2023/5/59975_0s.png)
微信小程序获取手机号,后端JAVA解密流程代码
2023-11-29 07:57:26
java中Class.getMethods()和Class.getDeclaredMethods()方法的区别
2021-05-28 23:05:46