How to Digitally Sign PDF with Timestamp Server in C#, VB.NET

Digital timestamps mark a PDF signature with the time and date as proof of integrity. A timestamp shows that the contents of the document existed at a point in time, and are unchanged. This article is going to introduce how to digitally sign a PDF document with a timestamp server by using Spire.PDF.

Code Snippets

[C#]
//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]
'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")

Output

How to Digitally Sign PDF with Timestamp Server in C#, VB.NET