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.

PDF Digital Signature Screenshot
Upload your file (Drag file here)
using GemBox.Document;
using GemBox.Document.Drawing;
using System.Linq;

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

        DocumentModel document = DocumentModel.Load("%InputFileName%");

        // 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, "%#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 = "%#GemBoxExampleExplorer.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 GemBox.Document
Imports GemBox.Document.Drawing
Imports System.Linq

Module Program

    Sub Main()

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

        Dim document As DocumentModel = DocumentModel.Load("%InputFileName%")

        ' 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, "%#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 = "%#GemBoxExampleExplorer.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 example or download examples from GitHub.