对pdf文档进行数字签名时添加可信时间戳,可以有效确认文档内容(如合同、协议)的生成时间。本教程将展示如何使用spire.pdf对pdf添加带时间戳的电子签名。
c#
//创建pdfdocument对象,并加载文档
pdfdocument doc = new pdfdocument();
doc.loadfromfile(@"c:\users\administrator\desktop\example.pdf");
//加载pfx证书
pdfcertificate cert = new pdfcertificate(@"c:\users\administrator\desktop\gary.pfx", "e-iceblue");
//添加数字签名到指定位置
pdfsignature signature = new pdfsignature(doc, doc.pages[0], cert, "signature");
signature.bounds = new rectanglef(new pointf(350, 550), new sizef(200, 100));
//设置数字签名内容
signature.signdetailsfont = new pdftruetypefont(new font("宋体", 10f, fontstyle.regular), true);
signature.namelabel = "签字人:gary";
signature.locationinfolabel = "地点:";
signature.locationinfo = "中国,成都";
signature.reasonlabel = "原因: ";
signature.reason = "证明文档有效性";
signature.datelabel = "日期: ";
signature.date = datetime.now;
signature.contactinfolabel = "联系电话: ";
signature.contactinfo = "028-81705109";
signature.documentpermissions = pdfcertificationflags.allowformfill | pdfcertificationflags.forbidchanges;
signature.graphicsmode = graphicmode.signimageandsigndetail;
signature.signimagesource = pdfimage.fromfile(@"c:\users\administrator\desktop\company-logo.jpg");
//配置时间戳服务器
string url = "http://timestamp.wosign.com/rfc3161";
signature.configuretimestamp(url);
//保存文档
doc.savetofile("output.pdf");
vb.net
'创建pdfdocument对象,并加载文档
dim doc as new pdfdocument()
doc.loadfromfile("c:\users\administrator\desktop\example.pdf")
'加载pfx证书
dim cert as new pdfcertificate("c:\users\administrator\desktop\gary.pfx", "e-iceblue")
'添加数字签名到指定位置
dim signature as new pdfsignature(doc, doc.pages(0), cert, "signature")
signature.bounds = new rectanglef(new pointf(350, 550), new sizef(200, 100))
'设置数字签名内容
signature.signdetailsfont = new pdftruetypefont(new font("宋体", 10f, fontstyle.regular), true)
signature.namelabel = "签字人:gary"
signature.locationinfolabel = "地点:"
signature.locationinfo = "中国,成都"
signature.reasonlabel = "原因: "
signature.reason = "证明文档有效性"
signature.datelabel = "日期: "
signature.[date] = datetime.now
signature.contactinfolabel = "联系电话: "
signature.contactinfo = "028-81705109"
signature.documentpermissions = pdfcertificationflags.allowformfill or pdfcertificationflags.forbidchanges
signature.graphicsmode = graphicmode.signimageandsigndetail
signature.signimagesource = pdfimage.fromfile("c:\users\administrator\desktop\company-logo.jpg")
'配置时间戳服务器
dim url as string = "http://timestamp.wosign.com/rfc3161"
signature.configuretimestamp(url)
'保存文档
doc.savetofile("output.pdf")