Sign Documents with LEADDocument - C# .NET 6

This tutorial shows how to add a signature image to a document in a C# .NET 6 application using the LEADTOOLS SDK.

Summary This tutorial covers how to add a signature image to a LEADDocument in a C# .NET 6 application.
Completion Time 30 minutes
Visual Studio Project Download tutorial project (6 KB)
Platform C# .NET 6 Console Application
IDE Visual Studio 2022
Runtime Target .NET 6 or Higher
Development License Download LEADTOOLS
Try it in another language
  • C#: .NET 6+ (Console)

  • Python: Python

Required Knowledge

Get familiar with the basic steps of creating a project by reviewing the Add References and Set a License tutorial, before working on the Sign Documents with LEADDocument - C# .NET 6 tutorial.

Create the Project and Add LEADTOOLS References

Start with a copy of the project created in the Add References and Set a License tutorial. If you do not have that project, follow the steps in that tutorial to create it.

The references needed depend upon the purpose of the project.

If using NuGet references, this tutorial requires the following NuGet package:

If local DLL references are used, the following DLLs are needed. The DLLs are located at <INSTALL_DIR>\LEADTOOLS22\Bin\net\:

For a complete list of which DLL files are required for your application, refer to Files to be Included With Your Application.

Set the License File

The License unlocks the features needed for the project. It must be set before any toolkit function is called. For details, including tutorials for different platforms, refer to Setting a Runtime License.

There are two types of runtime licenses:

Add LEADDocument and Sign Document Code

With the project created, the references added, and the license set, coding can begin.

In the Solution Explorer, open Program.cs. Add the following statements to the using block at the top of Program.cs.

// Using block at the top 
using Leadtools; 
using Leadtools.Document; 
using Leadtools.Document.Converter; 

In the Main() method add the following code:

static void Main(string[] args) 
    var pdfToSign = @"C:\LEADTOOLS22\Resources\Images\RentalLeaseAgreement.pdf"; 
    using var document = DocumentFactory.LoadFromFile(pdfToSign, new LoadDocumentOptions()); 
    // Define signature and resources 
    var resources = document.FormFields.GetResources(); 
    var signature = resources.CreateSignature(); 
    // SignerName and SignerInitial are optional fields 
    signature.SignerName = "John D."; 
    signature.SignerInitials = "JD"; 
    // Set the image for the signature 
    signature.SignatureImage = DocumentFactory.RasterCodecsTemplate.Load("Dotnet-Console-Sign-Documents-With-LEADDocument.png"); 
    // If you would like to add an image for initial fields 
    //signature.InitialsImage = DocumentFactory.RasterCodecsTemplate.Load(@"PATH_TO_INITIAL_IMAGE"); 
    // Update the document resources 
    // Now we have the resource ready, we can create the signatures fields 
    var signatureField = new DocumentSignatureFormField() 
        Bounds = new LeadRectD(3200, 600, 1800, 800), // Place the signature on the signature line in the document 
        SignerID = signature.SignerID, // Link the signature field to the Document Signature Resource 
        Signed = true 
    // Create a container and add the signature field to it. Use page 7 for this document 
    var container = new DocumentFormFieldsContainer(); 
    container.PageNumber = 7; 
    if (document.IsReadOnly) document.IsReadOnly = false; 
    // Set the form fields containers in LEAD Document 
    document.FormFields.SetFormFields(new DocumentFormFieldsContainer[] { container }); 
    var converter = new DocumentConverter(); 
    var job = converter.Jobs.CreateJob(new DocumentConverterJobData 
        Document = document, 
        DocumentFormat = Leadtools.Document.Writer.DocumentFormat.Pdf, 
        OutputDocumentFileName = Path.Combine(Path.GetDirectoryName(pdfToSign), Path.GetFileNameWithoutExtension(pdfToSign) + "_signed.pdf") 
    if (job.Errors.Count > 0) 
        foreach (var error in job.Errors) 
            Console.WriteLine($"Error: {error.Error.Message}"); 
        Console.WriteLine($"Signed and saved to: {job.OutputDocumentFiles.First()}"); 

Run the Project

Run the project by pressing F5, or by selecting Debug -> Start Debugging.

If the steps were followed correctly, the console appears and the application loads the PDF document, adds a signature to the 7th page, and exports the document.

Signature Image


This tutorial showed how to load a document and sign it, using a PNG signature image. Also, it covered how to use the LEADDocument, DocumentFormFieldsContainer, DocumentSignatureFormField, and DocumentConverter classes.

See Also

Help Version 22.0.2024.3.20
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.

Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.