GemBox.Document is a .NET component that enables you to read, write, edit, convert, and print document files from your .NET applications using one simple API.

Create digitally signed PDF in C# and VB.NET

A PDF digital signature enables you to authenticate a document to establish that the sender of the document is who they say they are and the content of the document has not been tampered with.

The following example shows how to create a digitally signed PDF document.

Certificate file: GemBoxSampleExplorer.pfx.

Signature file: GemBoxSignature.png.

Screenshot
PDF Digital Signature Screenshot

See the full code below, use Run Example to execute.

Upload your file(Drag files here)

Download a sample file

using System;
using GemBox.Document;
using GemBox.Document.Drawing;
using System.IO;
using System.Linq;

class Sample
{
    [STAThread]
    static void Main(string[] args)
    {
        // If using Professional version, put your serial key below.
        ComponentInfo.SetLicense("FREE-LIMITED-KEY");

        DocumentModel document = DocumentModel.Load("DigitalSignature.docx");

        string pathToResources = "Resources";

        // Signature line added with MS Word -> Insert tab -> Signature Line button by default has description 'Microsoft Office Signature Line...'.
        var signatureLine = document.GetChildElements(true).OfType<DrawingElement>().FirstOrDefault(
            de => de.Metadata.Description == "Microsoft Office Signature Line...");

        var signature = new Picture(document, Path.Combine(pathToResources, "GemBoxSignature.png"));

        // Signature in this document will be 1.5 cm right of TopLeft position of signature line 
        // and 0.5 cm below of TopLeft position of signature line.
        signature.Layout = Layout.Floating(
            new HorizontalPosition(1.5, LengthUnit.Centimeter, HorizontalPositionAnchor.Page),
            new VerticalPosition(0.5, LengthUnit.Centimeter, VerticalPositionAnchor.Page),
            signature.Layout.Size);

        var options = new PdfSaveOptions()
        {
            DigitalSignature =
            {
                CertificatePath = Path.Combine(pathToResources, "GemBoxSampleExplorer.pfx"),
                CertificatePassword = "GemBoxPassword",
                // Placeholder where signature should be visualized.
                SignatureLine = signatureLine,
                // Visual representation of digital signature.
                Signature = signature
            }
        };

        document.Save("PDF Digital Signature.pdf", options);
    }
}
Imports System
Imports GemBox.Document
Imports GemBox.Document.Drawing
Imports System.IO
Imports System.Linq

Module Samples

    Sub Main()

        ' If using Professional version, put your serial key below.
        ComponentInfo.SetLicense("FREE-LIMITED-KEY")

        Dim document As DocumentModel = DocumentModel.Load("DigitalSignature.docx")

        Dim pathToResources As String = "Resources"

        ' Signature line added with MS Word -> Insert tab -> Signature Line button by default has description 'Microsoft Office Signature Line...'.
        Dim signatureLine As DrawingElement = document.GetChildElements(True).OfType(Of DrawingElement)().FirstOrDefault(
            Function(de) de.Metadata.Description = "Microsoft Office Signature Line...")

        Dim signature = New Picture(document, Path.Combine(pathToResources, "GemBoxSignature.png"))

        ' Signature in this document will be 1.5 cm right of TopLeft position of signature line 
        ' and 0.5 cm below of TopLeft position of signature line.
        signature.Layout = Layout.Floating(
            New HorizontalPosition(1.5, LengthUnit.Centimeter, HorizontalPositionAnchor.Page),
            New VerticalPosition(0.5, LengthUnit.Centimeter, VerticalPositionAnchor.Page),
            signature.Layout.Size)

        Dim options = New PdfSaveOptions()
        Dim digitalSignature = options.DigitalSignature

        digitalSignature.CertificatePath = Path.Combine(pathToResources, "GemBoxSampleExplorer.pfx")
        digitalSignature.CertificatePassword = "GemBoxPassword"
        ' Placeholder where signature should be visualized.
        digitalSignature.SignatureLine = signatureLine
        ' Visual representation of digital signature.
        digitalSignature.Signature = signature

        document.Save("PDF Digital Signature.pdf", options)

    End Sub

End Module

Check next sample.