C# 在PDF中添加可视化数字签名

 时间:2024-10-12 12:36:24

1、在VS中通过Nuget安装Spire.PDF,步骤如图:

C# 在PDF中添加可视化数字签名
C# 在PDF中添加可视化数字签名
C# 在PDF中添加可视化数字签名

2、安装结果:

C# 在PDF中添加可视化数字签名

3、C# 代码:using Spire.Pd酆璁冻嘌f;using Spire.Pdf.Graphics;using Sp足毂忍珩ire.Pdf.Interactive.DigitalSignatures;using System.Drawing;using System.Security.Cryptography.X509Certificates;namespace VisibleDigitalSignature{ class Program { static void Main(string[] args) { //加载PDF测试文档 PdfDocument pdf = new PdfDocument(); pdf.LoadFromFile("test.pdf"); //获取PDF文档中的第5页 PdfPageBase page = pdf.Pages[4]; //在页面中的指定位置添加可视化签名 X509Certificate2 x509 = new X509Certificate2("cer.pfx", "e-iceblue"); PdfOrdinarySignatureMaker signatureMaker = new PdfOrdinarySignatureMaker(pdf, x509); IPdfSignatureAppearance signatureAppearance = new PdfCustomSignatureAppearance(); signatureMaker.MakeSignature("signName_" , page, page.ActualSize.Width-240,page.ActualSize.Height-200,150,150, signatureAppearance); //保存文档 pdf.SaveToFile("VisibleDigitalSignature.pdf", FileFormat.PDF); System.Diagnostics.Process.Start("VisibleDigitalSignature.pdf"); pdf.Close(); } public class PdfCustomSignatureAppearance : IPdfSignatureAppearance { public void Generate(PdfCanvas g) { float fontSize = 15; PdfTrueTypeFont font = new PdfTrueTypeFont(new Font("Arial", fontSize), true); float lineHeight = fontSize; g.DrawString("Sign Here:", font, PdfBrushes.Black, new PointF(0, 0)); g.DrawImage(PdfImage.FromFile("sign.png"), new PointF(20, 20)); } } }}

4、数字签名效果:

C# 在PDF中添加可视化数字签名
  • 批处理怎么删除指定文件夹文件
  • bat中for命令/d扩展用法
  • 临时文件夹无写入权限不能安装
  • 怎样监测网页中按钮的鼠标单击事件
  • 批处理获取当前时间点
  • 热门搜索
    团结友爱手抄报图片 清明手抄报资料大全 健康手抄报的内容 弘扬传统文化手抄报 保护动物手抄报内容 少先队员手抄报内容 初中英语手抄报资料 孝敬父母手抄报图片 长城手抄报图片 有关运动会的手抄报