阅读量:3
Spire.PDF for .NET 是一款独立 PDF 控件,用于 .NET 程序中创建、编辑和操作 PDF 文档。使用 Spire.PDF 类库,开发人员可以新建一个 PDF 文档或者对现有的 PDF 文档进行处理,且无需安装 Adobe Acrobat。
E-iceblue 功能类库Spire 系列文档处理组件均由中国本土团队研发,不依赖第三方软件,不受其他国家的技术或法律法规限制,同时适配国产操作系统如中科方德、中标麒麟等,兼容国产文档处理软件 WPS(如 .wps/.et/.dps 等格式
Spire.PDF for.net下载 Spire.PDF for java下载
数字时间戳用时间和日期标记 PDF 签名,作为完整性证明。时间戳表明文档的内容在某个时间点存在且未更改。本文将介绍如何使用 Spire.PDF 通过时间戳服务器对 PDF 文档进行数字签名。
代码片段
[C#]
using Spire.Pdf; using Spire.Pdf.Graphics; using Spire.Pdf.Security; using System.Drawing; namespace SignPDFwithTimestamp { class Program { static void Main(string[] args) { //create a PdfDocument object and load a PDF file PdfDocument doc = new PdfDocument(); doc.LoadFromFile(@"C:\Users\Administrator\Desktop\Example.pdf"); //load the certificate .pfx file PdfCertificate cert = new PdfCertificate(@"C:\Users\Administrator\Desktop\gary.pfx", "e-iceblue"); //add a signature to the specified position PdfSignature signature = new PdfSignature(doc, doc.Pages[0], cert, "signature"); signature.Bounds = new RectangleF(new PointF(350, 700), new SizeF(180, 90)); //set the signature content signature.NameLabel = "Digitally signed by:Gary"; signature.LocationInfoLabel = "Location:"; signature.LocationInfo = "CN"; signature.ReasonLabel = "Reason: "; signature.Reason = "Ensure authenticity"; signature.ContactInfoLabel = "Contact Number: "; 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"); //configure a timestamp server string url = "http://timestamp.wosign.com/rfc3161"; signature.ConfigureTimestamp(url); //save to file doc.SaveToFile("output.pdf"); } } }
[VB.NET]
Imports Spire.Pdf Imports Spire.Pdf.Graphics Imports Spire.Pdf.Security Imports System.Drawing Namespace SignPDFwithTimestamp Class Program Private Shared Sub Main(args As String()) 'create a PdfDocument object and load a PDF file Dim doc As PdfDocument = New PdfDocument() doc.LoadFromFile("C:\Users\Administrator\Desktop\Example.pdf") 'load the certificate .pfx file Dim cert As PdfCertificate = New PdfCertificate("C:\Users\Administrator\Desktop\gary.pfx","e-iceblue") 'add a signature to the specified position Dim signature As PdfSignature = New PdfSignature(doc,doc.Pages(0),cert,"signature") signature.Bounds = New RectangleF(New PointF(350, 700), New SizeF(180, 90)) 'set the signature content signature.NameLabel = "Digitally signed by:Gary" signature.LocationInfoLabel = "Location:" signature.LocationInfo = "CN" signature.ReasonLabel = "Reason: " signature.Reason = "Ensure authenticity" signature.ContactInfoLabel = "Contact Number: " 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") 'configure a timestamp server Dim url As String = "http://timestamp.wosign.com/rfc3161" signature.ConfigureTimestamp(url) 'save to file doc.SaveToFile("output.pdf") End Sub End Class End Namespace
以上便是如何用时间戳服务器对 PDF 进行数字签名,如果您有其他问题也可以继续浏览本系列文章,获取相关教程~