Iron Software. C# & .Net Component Library Developers
  • Products
    Read, edit, and sign PDFs Image to text in 127 languages Read and write QR & Barcodes No Office Interop required Extract structured data from websites 40% off Bundles Purchase a license for one product, get the second 40% off Contact our Team
  • About Us
  • Home
  • Licensing
  • Get Started
  • Languages
  • Code Examples
  • Tutorials
  • Support
IronOCR Library for C#
  • Home
  • Licensing
  • Get Started
  • Languages
  • Code Examples
  • Tutorials
  • Support
  • Download Free
IronOCR
IronOCR
Code Examples
  1. IronOCR
  2. Code Examples
  3. Detailed OCR Results
nuget   download  help
IronOCR
OCR in 1 line of code
PDF OCR Text Extraction
OCR with Barcode & QR Reading
125 International OCR Languages
Fixing Low Quality Scans & Images
Fast OCR Configuration
OCR Image Optimization Filters
OcrResult Class
Create Searchable PDFs by OCR
Tesseract 5 for .NET
Tesseract 4 for .NET
Tesseract 3 Legacy for .NET
Tesseract Detailed Configuration
OcrInput Class
OCR a Region of an Image
TIFF to Serchable PDF Converter
Image Resolution Optimization (DPI)
MultiThreaded Tesseract OCR
OCR for MultiPage TIFF Files
Make any PDF have Searchable, Copyable Text
Using Custom Tesseract Language Files
Multiple Languages for 1 Document
Exporting Images of OCR Elements

OcrResult Class

using IronOcr;
using System.Drawing; //for image export

// We can delve deep into OCR results as an object model of
// Pages, Barcodes, Paragraphs, Lines, Words and Characters
// This allows us to explore, export and draw OCR content using other APIs/
var Ocr = new IronTesseract();
Ocr.Configuration.EngineMode = TesseractEngineMode.TesseractAndLstm;
Ocr.Configuration.ReadBarCodes = true;
using (var Input = new OcrInput(@"example.tiff"))
{
    OcrResult Result = Ocr.Read(Input);
    foreach (var Page in Result.Pages)
    {
        // Page object
        int PageNumber = Page.PageNumber;
        string PageText = Page.Text;
        int PageWordCount = Page.WordCount;
        // null if we dont set Ocr.Configuration.ReadBarCodes = true;
        OcrResult.Barcode[] Barcodes = Page.Barcodes;
        System.Drawing.Bitmap PageImage = Page.ToBitmap(Input);
        int PageWidth = Page.Width;
        int PageHeight = Page.Height;
        foreach (var Paragraph in Page.Paragraphs)
        {
            // Pages -> Paragraphs
            int ParagraphNumber = Paragraph.ParagraphNumber;
            String ParagraphText = Paragraph.Text;
            System.Drawing.Bitmap ParagraphImage = Paragraph.ToBitmap(Input);
            int ParagraphX_location = Paragraph.X;
            int ParagraphY_location = Paragraph.Y;
            int ParagraphWidth = Paragraph.Width;
            int ParagraphHeight = Paragraph.Height;
            double ParagraphOcrAccuracy = Paragraph.Confidence;
            OcrResult.TextFlow paragrapthText_direction = Paragraph.TextDirection;
            foreach (var Line in Paragraph.Lines)
            {
                // Pages -> Paragraphs -> Lines
                int LineNumber = Line.LineNumber;
                String LineText = Line.Text;
                System.Drawing.Bitmap LineImage = Line.ToBitmap(Input); ;
                int LineX_location = Line.X;
                int LineY_location = Line.Y;
                int LineWidth = Line.Width;
                int LineHeight = Line.Height;
                double LineOcrAccuracy = Line.Confidence;
                double LineSkew = Line.BaselineAngle;
                double LineOffset = Line.BaselineOffset;
                foreach (var Word in Line.Words)
                {
                    // Pages -> Paragraphs -> Lines -> Words
                    int WordNumber = Word.WordNumber;
                    String WordText = Word.Text;
                    System.Drawing.Image WordImage = Word.ToBitmap(Input);
                    int WordX_location = Word.X;
                    int WordY_location = Word.Y;
                    int WordWidth = Word.Width;
                    int WordHeight = Word.Height;
                    double WordOcrAccuracy = Word.Confidence;
                    if (Word.Font != null)
                    {
                        // Word.Font is only set when using Tesseract Engine Modes rather than LTSM
                        String FontName = Word.Font.FontName;
                        double FontSize = Word.Font.FontSize;
                        bool IsBold = Word.Font.IsBold;
                        bool IsFixedWidth = Word.Font.IsFixedWidth;
                        bool IsItalic = Word.Font.IsItalic;
                        bool IsSerif = Word.Font.IsSerif;
                        bool IsUnderLined = Word.Font.IsUnderlined;
                        bool IsFancy = Word.Font.IsCaligraphic;
                    }
                    foreach (var Character in Word.Characters)
                    {
                        // Pages -> Paragraphs -> Lines -> Words -> Characters
                        int CharacterNumber = Character.CharacterNumber;
                        String CharacterText = Character.Text;
                        System.Drawing.Bitmap CharacterImage = Character.ToBitmap(Input);
                        int CharacterX_location = Character.X;
                        int CharacterY_location = Character.Y;
                        int CharacterWidth = Character.Width;
                        int CharacterHeight = Character.Height;
                        double CharacterOcrAccuracy = Character.Confidence;
                        // Output alternative symbols choices and their probability.
                        // Very useful for spellchecking
                        OcrResult.Choice[] Choices = Character.Choices;
                    }
                }
            }
        }
    }
}
Imports IronOcr
Imports System.Drawing 'for image export

' We can delve deep into OCR results as an object model of
' Pages, Barcodes, Paragraphs, Lines, Words and Characters
' This allows us to explore, export and draw OCR content using other APIs/
Private Ocr = New IronTesseract()
Ocr.Configuration.EngineMode = TesseractEngineMode.TesseractAndLstm
Ocr.Configuration.ReadBarCodes = True
Using Input = New OcrInput("example.tiff")
	Dim Result As OcrResult = Ocr.Read(Input)
	For Each Page In Result.Pages
		' Page object
		Dim PageNumber As Integer = Page.PageNumber
		Dim PageText As String = Page.Text
		Dim PageWordCount As Integer = Page.WordCount
		' null if we dont set Ocr.Configuration.ReadBarCodes = true;
		Dim Barcodes() As OcrResult.Barcode = Page.Barcodes
		Dim PageImage As System.Drawing.Bitmap = Page.ToBitmap(Input)
		Dim PageWidth As Integer = Page.Width
		Dim PageHeight As Integer = Page.Height
		For Each Paragraph In Page.Paragraphs
			' Pages -> Paragraphs
			Dim ParagraphNumber As Integer = Paragraph.ParagraphNumber
			Dim ParagraphText As String = Paragraph.Text
			Dim ParagraphImage As System.Drawing.Bitmap = Paragraph.ToBitmap(Input)
			Dim ParagraphX_location As Integer = Paragraph.X
			Dim ParagraphY_location As Integer = Paragraph.Y
			Dim ParagraphWidth As Integer = Paragraph.Width
			Dim ParagraphHeight As Integer = Paragraph.Height
			Dim ParagraphOcrAccuracy As Double = Paragraph.Confidence
			Dim paragrapthText_direction As OcrResult.TextFlow = Paragraph.TextDirection
			For Each Line In Paragraph.Lines
				' Pages -> Paragraphs -> Lines
				Dim LineNumber As Integer = Line.LineNumber
				Dim LineText As String = Line.Text
				Dim LineImage As System.Drawing.Bitmap = Line.ToBitmap(Input)

				Dim LineX_location As Integer = Line.X
				Dim LineY_location As Integer = Line.Y
				Dim LineWidth As Integer = Line.Width
				Dim LineHeight As Integer = Line.Height
				Dim LineOcrAccuracy As Double = Line.Confidence
				Dim LineSkew As Double = Line.BaselineAngle
				Dim LineOffset As Double = Line.BaselineOffset
				For Each Word In Line.Words
					' Pages -> Paragraphs -> Lines -> Words
					Dim WordNumber As Integer = Word.WordNumber
					Dim WordText As String = Word.Text
					Dim WordImage As System.Drawing.Image = Word.ToBitmap(Input)
					Dim WordX_location As Integer = Word.X
					Dim WordY_location As Integer = Word.Y
					Dim WordWidth As Integer = Word.Width
					Dim WordHeight As Integer = Word.Height
					Dim WordOcrAccuracy As Double = Word.Confidence
					If Word.Font IsNot Nothing Then
						' Word.Font is only set when using Tesseract Engine Modes rather than LTSM
						Dim FontName As String = Word.Font.FontName
						Dim FontSize As Double = Word.Font.FontSize
						Dim IsBold As Boolean = Word.Font.IsBold
						Dim IsFixedWidth As Boolean = Word.Font.IsFixedWidth
						Dim IsItalic As Boolean = Word.Font.IsItalic
						Dim IsSerif As Boolean = Word.Font.IsSerif
						Dim IsUnderLined As Boolean = Word.Font.IsUnderlined
						Dim IsFancy As Boolean = Word.Font.IsCaligraphic
					End If
					For Each Character In Word.Characters
						' Pages -> Paragraphs -> Lines -> Words -> Characters
						Dim CharacterNumber As Integer = Character.CharacterNumber
						Dim CharacterText As String = Character.Text
						Dim CharacterImage As System.Drawing.Bitmap = Character.ToBitmap(Input)
						Dim CharacterX_location As Integer = Character.X
						Dim CharacterY_location As Integer = Character.Y
						Dim CharacterWidth As Integer = Character.Width
						Dim CharacterHeight As Integer = Character.Height
						Dim CharacterOcrAccuracy As Double = Character.Confidence
						' Output alternative symbols choices and their probability.
						' Very useful for spellchecking
						Dim Choices() As OcrResult.Choice = Character.Choices
					Next Character
				Next Word
			Next Line
		Next Paragraph
	Next Page
End Using
Read more
Try IronOCR free for development
Download Free
C# Object Reference and Get Started Tutorials
Object Reference
C# Library Licensing
Licensing
.Net Developer Support
Ask a Question

OcrResult Class

IronOCR returns an advanced result object for each page it scans using Tesseract 3,4 or 5. This contains location data, images, text, statistical confidence, alternative symbol choices, font-names, font-sizes decoration and weights, rotation and position for each:

  • Page
  • Paragraph
  • Line of Text
  • Word
  • Individual Character
  • and Barcode

Previous Example
Next Example

The OCR Solution for your .Net Applications...

.Net Developer Support

Human Support

Talk directly with our development team

Ask a Question
C# Object Reference and Get Started Tutorials

Documentation

Clear online manuals in plain English.

View Documentation
C# Library Licensing

Simple Licensing

Free development license. Commercial from $399.

Browse Options
Install The C# OCR library

Get Started Now

Get started in minutes with NuGet or DLL.

Install & Try Now
Try IronOCR for Free
Get Set Up in 5 Minutes
C# Nuget Library for PDF
Install with NuGet
Version 2020.12.2
Install-Package IronOcr
nuget.org/packages/IronOcr/
  1. In Solution Explorer, right-click References, Manage NuGet Packages
  2. Select Browse and search "IronOCR"
  3. Select the package and install
C# PDF DLL
Download DLL
Version 2020.12.2
Download Now
Manually install into your project
  1. Download and unzip IronOCR to a location such as ~/Libs within your Solution directory
  2. In Visual Studio Solution Explorer, right click References. Select Browse, "IronOCR.dll"
Licenses from $399

Have a question? Get in touch with our development team.

Install with Nuget
C# Software Library Developers

Copyright © 2013-2021
Iron Software

Terms | Privacy

    Iron Software LLC

    205 N. Michigan Ave.
    Chicago, IL 60611
    USA

    +1 (312) 252-3088

    Contact Team Iron

    Products

    • IronPDF
    • IronOCR
    • IronBarcode
    • IronXL
    • IronWebScraper

    Information

    • Ask a Question
    • Documentation
    • Tutorials
    • Object Reference
    • About Us