Recognize Handwritten Text From Images With ICR- C# .NET 6

This tutorial shows how to run ICR on a given image in a C# .NET application using the LEADTOOLS SDK.

Summary This tutorial covers how to use OcrEngineType to run LEADTOOLS ICR on an image in a C# .NET Console application.
Completion Time 20 minutes
Visual Studio Project Download tutorial project (1 KB)
Platform C# .NET Console Application
IDE Visual Studio 2022
Runtime Target .NET 6 or Higher
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 Recognize Handwritten Text From Images With ICR- C# .NET 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 package:

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:

Initialize the IOcrEngine and Add ICR 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 System; 
using System.IO; 
using Leadtools; 
using Leadtools.Ocr; 

Add a new method to the Program class named RunICR(). Call the RunICR() method inside the Main() method below the set license code, as shown below.

static void Main(string[] args) 

Add the code below to the RunICR() method to run ICR (Intelligent Character Recognition) on the loaded image and export the results as a searchable PDF. For the purposes of this tutorial, the sample image in the following file path is used: <INSTALL_DIR>\LEADTOOLS23\Resources\Images\demoicr2.tif.

static void RunICR() 
    string _file = @"C:\LEADTOOLS23\Resources\Images\demoicr2.tif"; 
    using (IOcrEngine _ocrEngine = OcrEngineManager.CreateEngine(OcrEngineType.LEAD)) 
        _ocrEngine.Startup(null, null, null, @"C:\LEADTOOLS23\Bin\Common\OcrLEADRuntime"); 
        // Create an OCR document 
        using (IOcrDocument ocrDocument = _ocrEngine.DocumentManager.CreateDocument()) 
            IOcrPage _ocrPage = ocrDocument.Pages.AddPage(_file, null); 
            for (int i = 0; i < _ocrPage.Zones.Count; i++) 
                OcrZone tempZone = _ocrPage.Zones[i]; 
                tempZone.ZoneType = OcrZoneType.Icr; 
                _ocrPage.Zones[i] = tempZone; 
            ocrDocument.Save(@"C:\LEADTOOLS23\Resources\Images\icr.pdf", Leadtools.Document.Writer.DocumentFormat.Pdf, null); 

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 auto-generates zones with AutoZone for an image to be used in ICR, and outputs the recognized image to a searchable PDF.


This tutorial showed how to run ICR on an image and output it to a searchable PDF. We also covered how to use the IOcrEngine and IOcrPage interfaces, along with the OcrZone structure.

See Also

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

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