Digitally Sign PDF with Timestamp Server in C#/VB.NET

2019-03-13 09:40:25 Written by  support iceblue
Rate this item
(0 votes)

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#]
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

Output

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

Additional Info

  • tutorial_title: Digitally Sign PDF with Timestamp Server
Last modified on Sunday, 26 September 2021 01:40