Skip to footer content
USING IRONOCR

How to Create OCR Software Demo in C#

Optical Character Recognition (OCR) is a technology that transforms various document formats, including scanned paper documents, PDFs, digital files, or images of printed text taken with a digital camera, into editable and searchable machine-encoded text data.

IronOCR is a great OCR engine library that offers powerful OCR functionalities to developers. In this article, we will explore how to perform OCR using IronOCR with code examples with OCR Software Demo.

What is IronOCR?

IronOCR is a powerful .NET library designed to facilitate optical character recognition (OCR) within C# and VB.NET applications. Leveraging advanced algorithms and machine learning techniques, IronOCR can accurately extract text and content from scanned PDF files, images, and PDFs, making it easier to process, search, and analyze such files programmatically.

With its straightforward API and extensive features, developers can seamlessly integrate OCR capabilities into their applications to automate data extraction, document processing, data entry, and content management tasks. Whether you're working on business, with invoices, reports, automated data extraction, a searchable PDF, or any other text-rich documents, IronOCR offers a reliable solution to handle OCR requirements efficiently.

Getting Started with IronOCR

Before diving into the code examples, you need to install IronOCR via NuGet Package Manager. You can install IronOCR by running the following command in the Package Manager Console:

Install-Package IronOcr

Performing OCR with IronOCR

Basic Text Recognition

To perform basic text recognition using IronOCR, you can use the following code snippet:

using IronOcr;
using System;

class Program
{
    static void Main()
    {
        var ocrTesseract = new IronTesseract();
        using (var ocrInput = new OcrInput("ocr.png"))
        {
            var ocrResult = ocrTesseract.Read(ocrInput);
            string recognizedText = ocrResult.Text;
            Console.WriteLine(recognizedText);
        }
    }
}
using IronOcr;
using System;

class Program
{
    static void Main()
    {
        var ocrTesseract = new IronTesseract();
        using (var ocrInput = new OcrInput("ocr.png"))
        {
            var ocrResult = ocrTesseract.Read(ocrInput);
            string recognizedText = ocrResult.Text;
            Console.WriteLine(recognizedText);
        }
    }
}
Imports IronOcr
Imports System

Friend Class Program
	Shared Sub Main()
		Dim ocrTesseract = New IronTesseract()
		Using ocrInput As New OcrInput("ocr.png")
			Dim ocrResult = ocrTesseract.Read(ocrInput)
			Dim recognizedText As String = ocrResult.Text
			Console.WriteLine(recognizedText)
		End Using
	End Sub
End Class
$vbLabelText   $csharpLabel

This code uses IronOCR to perform optical character recognition (OCR) on an image file named "ocr.png". It initializes an IronTesseract object and reads the text layer of the image file into an OcrInput object.

The OCR result is then retrieved as recognizedText and printed to the console.

Output
- LOGO SHOP
- LOREM IPSUM
- DOLOR SITAMET CONSECTETUR
- ADIPISCING ELIT
- 1 LOREM IPSUM $3.20
- 2 ORNARE MALESUADA $9.50
- 3 PORTA FERMENTUM $5.90
- 4 SODALES ARCU $6.00
- 5 ELEIFEND $9.00
- 6 SEMNISIMASSA $0.50
- 7 DUIS FAMES DIS $7.60
- 8 FACILISIRISUS $810
- TOTAL AMOUNT $49.80
- CASH $50.00

Advanced OCR Options

IronOCR provides various options that enable you to customize the OCR process according to your image files and requirements. For example, you can specify the OCR language, adjust the image preprocessing settings, or enable text cleaning. Here's an example that demonstrates some of these advanced options:

using IronOcr;
using System;

class Program
{
    static void Main()
    {
        var ocr = new IronTesseract();
        using var ocrInput = new OcrInput();
        ocrInput.LoadImage(@"images\image.png");

        // Set OCR language to English
        ocr.Language = OcrLanguage.English;

        // Enable text cleaning and enhance the resolution
        ocrInput.DeNoise();
        ocrInput.EnhanceResolution(225);

        var result = ocr.Read(ocrInput);
        if (!string.IsNullOrEmpty(result.Text))
        {
            Console.WriteLine($"Recognized Text: {result.Text}");
        }
    }
}
using IronOcr;
using System;

class Program
{
    static void Main()
    {
        var ocr = new IronTesseract();
        using var ocrInput = new OcrInput();
        ocrInput.LoadImage(@"images\image.png");

        // Set OCR language to English
        ocr.Language = OcrLanguage.English;

        // Enable text cleaning and enhance the resolution
        ocrInput.DeNoise();
        ocrInput.EnhanceResolution(225);

        var result = ocr.Read(ocrInput);
        if (!string.IsNullOrEmpty(result.Text))
        {
            Console.WriteLine($"Recognized Text: {result.Text}");
        }
    }
}
Imports IronOcr
Imports System

Friend Class Program
	Shared Sub Main()
		Dim ocr = New IronTesseract()
		Dim ocrInput As New OcrInput()
		ocrInput.LoadImage("images\image.png")

		' Set OCR language to English
		ocr.Language = OcrLanguage.English

		' Enable text cleaning and enhance the resolution
		ocrInput.DeNoise()
		ocrInput.EnhanceResolution(225)

		Dim result = ocr.Read(ocrInput)
		If Not String.IsNullOrEmpty(result.Text) Then
			Console.WriteLine($"Recognized Text: {result.Text}")
		End If
	End Sub
End Class
$vbLabelText   $csharpLabel

The code uses IronOCR to perform OCR on an image file "image.png" located in the "images" folder. It sets the OCR language to English, cleans the image noise, and enhances its resolution. The recognized text from the image is extracted and then printed to the console.

How to Create OCR Software Demo in C#: Figure 1

Barcode Reading

IronOCR also supports barcode reading, allowing you to make software to extract barcode information from images. Here's a code example that demonstrates how to read a barcode using IronOCR:

using IronOcr;
using System;

class Program
{
    static void Main()
    {
        var ocrTesseract = new IronTesseract();
        ocrTesseract.Configuration.ReadBarCodes = true;

        using var ocrInput = new OcrInput();
        ocrInput.LoadImage(@"images\imageWithBarcode.png");

        var ocrResult = ocrTesseract.Read(ocrInput);
        foreach (var barcode in ocrResult.Barcodes)
        {
            Console.WriteLine(barcode.Value);
        }
    }
}
using IronOcr;
using System;

class Program
{
    static void Main()
    {
        var ocrTesseract = new IronTesseract();
        ocrTesseract.Configuration.ReadBarCodes = true;

        using var ocrInput = new OcrInput();
        ocrInput.LoadImage(@"images\imageWithBarcode.png");

        var ocrResult = ocrTesseract.Read(ocrInput);
        foreach (var barcode in ocrResult.Barcodes)
        {
            Console.WriteLine(barcode.Value);
        }
    }
}
Imports IronOcr
Imports System

Friend Class Program
	Shared Sub Main()
		Dim ocrTesseract = New IronTesseract()
		ocrTesseract.Configuration.ReadBarCodes = True

		Dim ocrInput As New OcrInput()
		ocrInput.LoadImage("images\imageWithBarcode.png")

		Dim ocrResult = ocrTesseract.Read(ocrInput)
		For Each barcode In ocrResult.Barcodes
			Console.WriteLine(barcode.Value)
		Next barcode
	End Sub
End Class
$vbLabelText   $csharpLabel

The code uses IronOCR to detect and read barcodes from an image file "imageWithBarcode.png" in the "images" folder. It configures IronOCR to enable barcode reading by setting ReadBarCodes to true. The detected barcode values are then printed to the console.

How to Create OCR Software Demo in C#: Figure 2

PDF Text Extraction

IronOCR can also extract text from PDFs and scanned documents. Here's a code example that demonstrates how to extract text from a PDF file using IronOCR:

using IronOcr;
using System;

class Program
{
    static void Main()
    {
        var ocrTesseract = new IronTesseract();
        using var ocrInput = new OcrInput();

        // OCR entire document
        ocrInput.LoadPdf("Email_Report.pdf");

        // Alternatively OCR selected page numbers
        int[] pages = { 1, 2, 3, 4, 5 };
        ocrInput.LoadPdfPages("example.pdf", pages, Password: "password");

        var ocrResult = ocrTesseract.Read(ocrInput);
        Console.WriteLine(ocrResult.Text);
    }
}
using IronOcr;
using System;

class Program
{
    static void Main()
    {
        var ocrTesseract = new IronTesseract();
        using var ocrInput = new OcrInput();

        // OCR entire document
        ocrInput.LoadPdf("Email_Report.pdf");

        // Alternatively OCR selected page numbers
        int[] pages = { 1, 2, 3, 4, 5 };
        ocrInput.LoadPdfPages("example.pdf", pages, Password: "password");

        var ocrResult = ocrTesseract.Read(ocrInput);
        Console.WriteLine(ocrResult.Text);
    }
}
Imports IronOcr
Imports System

Friend Class Program
	Shared Sub Main()
		Dim ocrTesseract = New IronTesseract()
		Dim ocrInput As New OcrInput()

		' OCR entire document
		ocrInput.LoadPdf("Email_Report.pdf")

		' Alternatively OCR selected page numbers
		Dim pages() As Integer = { 1, 2, 3, 4, 5 }
		ocrInput.LoadPdfPages("example.pdf", pages, Password:= "password")

		Dim ocrResult = ocrTesseract.Read(ocrInput)
		Console.WriteLine(ocrResult.Text)
	End Sub
End Class
$vbLabelText   $csharpLabel

The code uses IronOCR to perform OCR processing on a PDF document named "Email_Report.pdf". It can OCR the entire document using LoadPdf, or specific pages from "example.pdf" using LoadPdfPages with a password. The recognized text from the OCR operation is printed to the console.

How to Create OCR Software Demo in C#: Figure 3

Conclusion

IronOCR is a powerful .NET library that offers advanced OCR software capabilities, making it easy for developers to perform OCR tasks in their applications. In this article, we explored how to perform basic and advanced OCR Software Demo using IronOCR with code examples.

If you're working on a .NET project and need to integrate OCR functionality, IronOCR is definitely worth considering when looking at different OCR engines. Its ease of use, speed, flexibility, and extensive documentation make it a popular choice among developers for OCR automation tasks.

So why not give IronOCR a try and see how it can simplify your own OCR project development process? It may be the best OCR engine for your projects.

IronOCR offers a free trial license then starts from $749 USD which allows you to continue to get the most out of IronOCR in your projects.

To know more about IronOCR visit here.

Frequently Asked Questions

How can I perform OCR in C#?

You can perform OCR in C# using the IronOCR library. First, install it via the NuGet Package Manager with the command Install-Package IronOcr. Then, use the IronTesseract object to read text from images or PDFs and convert them into editable text.

What steps are involved in extracting text from an image using C#?

To extract text from an image in C#, use IronOCR by creating an instance of the IronTesseract object. Load your image, such as 'ocr.png', and call the Read() method to process the image and extract the text.

Can I customize the OCR process with IronOCR?

Yes, IronOCR allows you to customize the OCR process by setting options like the OCR language, enabling image preprocessing for noise reduction, and adjusting resolution to improve accuracy.

Is it possible to perform barcode reading with IronOCR?

Yes, IronOCR supports barcode reading. You can configure it to detect and extract barcode information from images by enabling the barcode reading feature within your OCR setup.

How do I extract text from a PDF using C#?

Using IronOCR, you can extract text from PDF files in C#. You can choose to OCR the entire document or specific pages by loading the PDF into IronTesseract and using its Read() method to extract the text.

What makes IronOCR a recommended choice for developers?

IronOCR is recommended for developers due to its comprehensive OCR features, ease of use, fast processing, and flexibility. It integrates seamlessly into .NET projects, allowing for efficient automation of OCR tasks.

Are there licensing options available for IronOCR?

IronOCR offers various licensing options, starting with a free trial. Developers can choose from different licenses to continue using IronOCR's full capabilities in their applications.

Where can I find code examples for using IronOCR?

You can find code examples for using IronOCR in the article 'OCR Software Demo in C# (Developer Tutorial).' The examples demonstrate basic text recognition, advanced OCR options, and barcode reading.

Kannaopat Udonpant
Software Engineer
Before becoming a Software Engineer, Kannapat completed a Environmental Resources PhD from Hokkaido University in Japan. While pursuing his degree, Kannapat also became a member of the Vehicle Robotics Laboratory, which is part of the Department of Bioproduction Engineering. In 2022, he leveraged his C# skills to join Iron Software's engineering ...Read More