How to Locate Digital Signature Date on PDFs Using C# and .NET

When working with digitally signed PDF documents, it is often necessary to check the date of signing the document. This can be crucial for legal purposes and record keeping. Using the library SautinSoft PDF .NET developers can programmatically determine the date of signing a digital signature in a PDF document using C# and .NET. This has several important goals:

  • Legal significance. The signature date can be critical for legal documents, contracts and agreements. She confirms exactly when the document was signed, which may be necessary to comply with the terms and conditions.
  • Audit and Tracking. In a corporate environment, it is important to be able to track when documents have been signed for audit and internal control purposes.
  • Authentication. The signature date helps to confirm the authenticity of the document and its immutability from the moment of signing.
  • Compliance with regulatory requirements. In some industries and jurisdictions, there are strict requirements for documents, including the need to specify the date of signing.

Follow the steps to achieve the desired result.

  1. Add SautinSoft.PDF from NuGet.
  2. Load a PDF document
  3. Find the digital signature and extract the creation date.
  4. Show the date to Console.

Output result:

Полный код

using System;
using System.IO;
using SautinSoft;
using SautinSoft.Pdf;
using SautinSoft.Pdf.Content;
using SautinSoft.Pdf.Forms;

namespace Sample
{
    class Sample
    {
        /// <summary>
        /// How to determine the signing date of a digital signature on a current pdf using C# and .NET
        /// </summary>
        /// <remarks>
        /// Details: https://sautinsoft.com/products/pdf/help/net/developer-guide/determine-the-signing-date-of-a-digital-signature-on-a-current-pdf-csharp-dotnet.php
        /// </remarks>
        static void Main(string[] args)
        {
            // Before starting this example, please get a free 100-day trial key:
            // https://sautinsoft.com/start-for-free/

            // Apply the key here:
            // PdfDocument.SetLicense("...");

            string inpFile = Path.GetFullPath(@"..\..\..\digital signature.pdf");
            
            using (PdfDocument document = PdfDocument.Load(inpFile))
            {
                var field = document.Form.Fields.FirstOrDefault(f => f is PdfSignatureField);
                if (field != null && field is PdfSignatureField signField)
                {
                    Console.WriteLine($"The signature date is {signField.Value.Date}.");
                }
                else
                {
                    Console.WriteLine("The PDF doesn't have a digital signature!");
                }
            }
        }
    }
}

Download

Option Infer On

Imports System
Imports System.IO
Imports SautinSoft
Imports SautinSoft.Pdf
Imports SautinSoft.Pdf.Content
Imports SautinSoft.Pdf.Forms

Namespace Sample
	Friend Class Sample
		''' <summary>
		''' How to determine the signing date of a digital signature on a current pdf using C# and .NET
		''' </summary>
		''' <remarks>
		''' Details: https://sautinsoft.com/products/pdf/help/net/developer-guide/determine-the-signing-date-of-a-digital-signature-on-a-current-pdf-csharp-dotnet.php
		''' </remarks>
		Shared Sub Main(ByVal args() As String)
			' Before starting this example, please get a free 100-day trial key:
			' https://sautinsoft.com/start-for-free/

			' Apply the key here:
			' PdfDocument.SetLicense("...");

			Dim inpFile As String = Path.GetFullPath("..\..\..\digital signature.pdf")

			Using document As PdfDocument = PdfDocument.Load(inpFile)
				Dim field = document.Form.Fields.FirstOrDefault(Function(f) TypeOf f Is PdfSignatureField)
				Dim tempVar As Boolean = TypeOf field Is PdfSignatureField
				Dim signField As PdfSignatureField = If(tempVar, CType(field, PdfSignatureField), Nothing)
				If field IsNot Nothing AndAlso tempVar Then
					Console.WriteLine($"The signature date is {signField.Value.Date}.")
				Else
					Console.WriteLine("The PDF doesn't have a digital signature!")
				End If
			End Using
		End Sub
	End Class
End Namespace

Download


Если вам нужен пример кода или у вас есть вопрос: напишите нам по адресу support@sautinsoft.ru или спросите в онлайн-чате (правый нижний угол этой страницы) или используйте форму ниже:



Вопросы и предложения всегда приветствуются!

Мы разрабатываем компоненты .Net с 2002 года. Мы знаем форматы PDF, DOCX, RTF, HTML, XLSX и Images. Если вам нужна помощь в создании, изменении или преобразовании документов в различных форматах, мы можем вам помочь. Мы напишем для вас любой пример кода абсолютно бесплатно.