Burn Annotations to a LEADDocument - Console C#

This tutorial shows how to create a C# Windows console that creates a new PDF document and burns annotations to it in an AnnContainer.

Overview  
Summary This tutorial covers how to create a new PDF document and burns annotations to it in a C# Windows Console application
Completion Time 30 minutes
Visual Studio Project Download tutorial project (3 KB)
Platform C# Windows Console Application
IDE Visual Studio 2017, 2019
Development License Download LEADTOOLS
Try it in another language

Required Knowledge

Before working on the Burn Annotations to a LEADDocument - Console C# tutorial, get familiar with the basic steps of creating a project by reviewing the Add References and Set a License tutorial.

Create the Project and Add the LEADTOOLS References

Start with a copy of the project created in the Add References and Set a License tutorial. If you don't 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 by one or the other of the following two methods (but not both). For this project, the following references are needed:

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>\LEADTOOLS21\Bin\Dotnet4\x64:

For a complete list of which Codec DLLs are required for specific formats, refer to File Format Support.

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 and local references and setting a license are covered in more detail in the Add References and Set a License tutorial.

Create a New PDF, Add a Page, 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 a new method called BurnAnnotations(string documentFile, string annFile) and call it inside the Main() method under SetLicense();. Add the below code to create a new virtual document, add a PDF document to the virtual document, burn annotations, and finalize and export to file using the Document Converter.

C#
// Using block at the top 
using System; 
using System.IO; 
using Leadtools; 
using Leadtools.Annotations.Rendering; 
using Leadtools.Document; 
using Leadtools.Document.Converter; 
C#
static void Main(string[] args) 
{ 
    string pdfFile = @"C:\LEADTOOLS21\Resources\Images\leadtools.pdf"; 
    string annFile = @"C:\LEADTOOLS21\Resources\Images\cannon.ann"; 
    SetLicense(); 
    BurnAnnotations(pdfFile, annFile); 
} 
C#
static void BurnAnnotations(string documentFile, string annFile) 
{ 
    LEADDocument virtualDocument = DocumentFactory.Create(new CreateDocumentOptions()); 
    var annUri = new Uri(annFile); 
    LoadDocumentOptions loadOptions = new LoadDocumentOptions(); 
    loadOptions.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 AnnWinFormsRenderingEngine()); 
    var jobData = new DocumentConverterJobData 
    { 
        AnnotationsMode = DocumentConverterAnnotationsMode.Embed, 
        Document = virtualDocument, 
        OutputDocumentFileName = @"C:\LEADTOOLS21\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 application runs and creates 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 21.0.2023.3.1
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.