Burn Annotations to a LEADDocument - C# .NET Core

This tutorial shows how to burn the annotations from an external XML file to a PDF document in a C# .NET Core application using the LEADTOOLS SDK.

Overview  
Summary This tutorial covers how to burn annotations to a PDF file using the LEADDocument class in a C# .NET Core application
Completion Time 30 minutes
Visual Studio Project Download tutorial project (1 KB)
Platform C# .NET Core Console Application
IDE Visual Studio 2017, 2019
Development License Download LEADTOOLS
Try it in another language

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 Burn Annotations to a LEADDocument - C# .NET Core 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. References can be added via NuGet packages.

This tutorial requires the following NuGet packages:

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:

Note

Adding LEADTOOLS NuGet references and setting a license are covered in more detail in the Add References and Set a License tutorial.

Add LEADDocument and Burn Annotations 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.

C#
// Using block at the top 
using System; 
using Leadtools; 
using Leadtools.Annotations.Rendering; 
using Leadtools.Document; 
using Leadtools.Document.Converter; 

Add a new method called BurnAnnotations(string documentFile, string annFile) and call it inside the Main() method under SetLicense();.

C#
static void Main(string[] args) 
{ 
    string pdfFile = @"FILE PATH TO PDF FILE"; 
    string annFile = @"FILE PATH TO ANNOTATIONS XML FILE"; 
 
    if (!SetLicense()) 
        Console.WriteLine("Error setting license"); 
    else 
        Console.WriteLine("License file set successfully"); 
 
    BurnAnnotations(pdfFile, annFile); 
} 

Add the below code to create a new virtual document, add a PDF document to the virtual document, burn annotations, and export the file using the Document Converter.

C#
static void BurnAnnotations(string documentFile, string annFile) 
{ 
    LEADDocument virtualDocument = DocumentFactory.Create(new CreateDocumentOptions()); 
    var annUri = new Uri(annFile); 
    LoadDocumentOptions loadOptions = new LoadDocumentOptions 
    { 
        AnnotationsUri = annUri, 
    }; 
    LEADDocument childDocument = DocumentFactory.LoadFromFile(documentFile, loadOptions); 
 
    virtualDocument.Pages.Add(childDocument.Pages[0]); 
 
    DocumentConverter docConverter = new DocumentConverter(); 
    docConverter.SetDocumentWriterInstance(new Leadtools.Document.Writer.DocumentWriter()); 
    docConverter.SetAnnRenderingEngineInstance(new AnnDrawRenderingEngine()); 
    var jobData = new DocumentConverterJobData 
    { 
        AnnotationsMode = DocumentConverterAnnotationsMode.Embed, 
        Document = virtualDocument, 
        OutputDocumentFileName = @"C:\LEADTOOLS22\Resources\Images\BurnAnnotationsDoc.pdf", 
        DocumentFormat = Leadtools.Document.Writer.DocumentFormat.Pdf, 
    }; 
    var job = docConverter.Jobs.CreateJob(jobData); 
    docConverter.Jobs.RunJob(job); 
    foreach (var error in job.Errors) 
        Console.WriteLine($"There was an error:{error.Error}"); 
} 

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 creates a virtual document, adds a PDF document to the virtual document, burns annotations to it, and exports the document to file.

Wrap-up

This tutorial showed how to create a new virtual document and burn annotations to it. Also, it covered how to use the LEADDocument, LoadDocumentOptions, and DocumentConverter classes.

See Also

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

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