Search Results for

    Show / Hide Table of Contents

    Class OcrResult

    A full document object model (DOM) for results when IronTesseract reads an image or OcrInput.

    Gives access to Text, Pages, Words, Paragraphs, Lines, Words, Characters, Images, Barcodes, Coordinates, Font information in granular detail.

    Inheritance
    System.Object
    OcrResult
    Implements
    IronSoftware.Abstractions.Ocr.IOcrResult
    IronSoftware.Abstractions.Absolute.IDocumentPageContainer<OcrResultPagesCollection>
    IronSoftware.Abstractions.Pdf.IDocumentWithExtractableText
    Namespace: IronOcr
    Assembly: IronOcr.dll
    Syntax
    public class OcrResult : Object

    OcrResult is the object you hold after IronTesseract reads an image or OcrInput, the full document object model for everything the engine recognized. Reach for it whenever a project needs more than a flat string of text: word positions, per-page structure, confidence scores, and the searchable PDF or hOCR export that downstream steps depend on. It is what IronTesseract.Read hands back, and it is distinct from the lighter single-purpose results such as OcrPhotoResult or OcrLicensePlateResult, which expose only a Text/Confidence trio for one scenario.

    A read produces one OcrResult. IronTesseract.Read returns it directly, so a typical flow constructs an IronTesseract, builds an OcrInput from images or a PDF, calls Read, and then walks the result. The structure spans the whole input: PageCount reports how many pages were read, Pages exposes the per-page collection, and the overall Confidence summarizes recognition quality across the document.

    The members fall into clear groups. For text, read Text for the full string or ExtractTextFromPage for a single page. For structure, iterate Pages, Paragraphs, Lines, Words, and Characters, with Blocks and Tables for layout regions and Barcodes for any codes found alongside the text. For output, call SaveAsSearchablePdf to produce a layered PDF, SaveAsHocrFile or SaveAsHocrString for hOCR, SaveAsHtmlString for HTML, or ToJson to serialize the whole model. EngineModeUsed and TesseractVersion record how the read ran, and Cancelled reports whether a cancellation token stopped it early.

    using IronOcr;
    
    var ocr = new IronTesseract();
    using var input = new OcrInput();
    input.LoadImage("scan.png");
    OcrResult result = ocr.Read(input);
    Console.WriteLine(result.Text);
    result.SaveAsSearchablePdf("searchable.pdf");

    The OCR results objects example walks the document model property by property, the read results how-to shows how to pull text and coordinates, and the searchable PDF example builds the layered export.

    Properties

    Barcodes

    Represents every barcode discovered in this OCR document. Developers must set ReadBarCodes = True for this feature to be active.

    Declaration
    public OcrResult.Barcode[] Barcodes { get; }
    Property Value
    Type Description
    OcrResult.Barcode[]

    Blocks

    Represents every block of text discovered in this OCR document in order of appearance. A Block is a collection of 1 or more paragraphs located closely together.

    Declaration
    public OcrResult.Block[] Blocks { get; }
    Property Value
    Type Description
    OcrResult.Block[]

    Cancelled

    Indicates that the Ocr reading was cancelled by the user or after a timeout

    Declaration
    public bool Cancelled { get; }
    Property Value
    Type Description
    System.Boolean

    Characters

    Represents every symbol (char) discovered in this OCR document in order of appearance.

    Declaration
    public OcrResult.Character[] Characters { get; }
    Property Value
    Type Description
    OcrResult.Character[]

    Confidence

    OCR statistical accuracy confidence as an average of every character.

    1 = 100%, 0 = 0%

    Declaration
    public double Confidence { get; }
    Property Value
    Type Description
    System.Double

    EngineModeUsed

    The TesseractEngineMode used to generate this OcrResult.

    Declaration
    public TesseractEngineMode EngineModeUsed { get; }
    Property Value
    Type Description
    TesseractEngineMode
    Remarks

    Only the LSTM engine is available, so this value is always LstmOnly.

    See Also
    TesseractEngineMode

    Lines

    Represents every line of text discovered in this OCR document in order of appearance.

    Declaration
    public OcrResult.Line[] Lines { get; }
    Property Value
    Type Description
    OcrResult.Line[]

    PageCount

    Declaration
    public int PageCount { get; }
    Property Value
    Type Description
    System.Int32

    Pages

    Represents every page within this OcrResult object.

    Declaration
    public OcrResultPagesCollection Pages { get; }
    Property Value
    Type Description
    OcrResultPagesCollection

    Paragraphs

    Represents every paragraph of text discovered in this OCR document in order of appearance.

    Declaration
    public OcrResult.Paragraph[] Paragraphs { get; }
    Property Value
    Type Description
    OcrResult.Paragraph[]

    Tables

    Represents every table that can be rationalized clearrly in this OCR document. To see tables in the OcrResult, access the Tables property. To enable table reading, set IronTesseract's Configuration.ReadDataTables to true.

     var Ocr = new IronTesseract();
     Ocr.Configuration.ReadDataTables = true;

    Declaration
    public OcrResult.Table[] Tables { get; }
    Property Value
    Type Description
    OcrResult.Table[]

    TesseractVersion

    The TesseractVersion used to generate this OcrResult.

    Declaration
    public string TesseractVersion { get; }
    Property Value
    Type Description
    System.String
    Remarks

    When this OcrResult is a combined result built from the per-page results captured during the read, the value is read through from the first completed page's result, since every page in a single Read() call uses the same Tesseract engine version.

    See Also
    TesseractVersion

    Text

    Returns the entire Text content of this OCR document. 4 System.Environment.NewLine characters will separate pages. This is truncated when the product is unlicensed.

    Declaration
    public string Text { get; set; }
    Property Value
    Type Description
    System.String

    Words

    Represents every word discovered in this OCR document in order of appearance.

    Declaration
    public OcrResult.Word[] Words { get; }
    Property Value
    Type Description
    OcrResult.Word[]

    Methods

    ExtractTextFromPage(Int32)

    Declaration
    public string ExtractTextFromPage(int PageIndex)
    Parameters
    Type Name Description
    System.Int32 PageIndex
    Returns
    Type Description
    System.String

    ExtractTextFromPages(IEnumerable<Int32>)

    Declaration
    public string ExtractTextFromPages(IEnumerable<int> PageIndices)
    Parameters
    Type Name Description
    System.Collections.Generic.IEnumerable<System.Int32> PageIndices
    Returns
    Type Description
    System.String

    FromJson(String)

    Deserializes the JSON to the OcrResult object.

    Declaration
    public static OcrResult FromJson(string json)
    Parameters
    Type Name Description
    System.String json

    A JSON string representation of the OcrResult.

    Returns
    Type Description
    OcrResult

    The deserialized OcrResult object from the JSON string.

    Exceptions
    Type Condition
    System.ArgumentNullException

    json is null

    FromJsonFile(String)

    Deserializes the JSON file to the OcrResult object.

    Declaration
    public OcrResult FromJsonFile(string Path)
    Parameters
    Type Name Description
    System.String Path
    Returns
    Type Description
    OcrResult
    Remarks

    Use the method FromJson(String) instead if you want deserialize from a JSON string.

    SaveAsHocrFile(String)

    Exports an hOCR version of the Tesseract results object document. This is an XHTML file which can be read as XML or HTML.

    https://en.wikipedia.org/wiki/HOCR

    Declaration
    public void SaveAsHocrFile(string Path)
    Parameters
    Type Name Description
    System.String Path

    The file path the xhtml file will be saved to.

    SaveAsHocrString()

    Exports an hOCR version of the Tesseract results object document as a string. This is an XHTML file which can be read as XML or HTML.

    https://en.wikipedia.org/wiki/HOCR

    Declaration
    public string SaveAsHocrString()
    Returns
    Type Description
    System.String

    SaveAsHtmlDocument(String, String, Int32, Boolean)

    Converts the OcrResult into an HTML Document eg.: example.html

    Declaration
    public void SaveAsHtmlDocument(string path, string title, int pdfPageMargin = 10, bool fullContentWidth = false)
    Parameters
    Type Name Description
    System.String path

    File path to save to

    System.String title

    Title for the HTML document

    System.Int32 pdfPageMargin

    Margin to use for PDF page

    System.Boolean fullContentWidth

    Optionally use full content width in the HTML

    Remarks

    IronTesseract's Configuration.RenderSearchablePdf flag must be set to true.

    SaveAsHtmlString(String, Int32, Boolean)

    Converts the OcrResult into an HTML string

    Declaration
    public string SaveAsHtmlString(string title, int pdfPageMargin, bool fullContentWidth)
    Parameters
    Type Name Description
    System.String title

    Title for the HTML document

    System.Int32 pdfPageMargin

    Margin to use for PDF page

    System.Boolean fullContentWidth

    Optionally use full content width in the HTML

    Returns
    Type Description
    System.String
    Remarks

    IronTesseract's Configuration.RenderSearchablePdf flag must be set to true.

    SaveAsSearchablePdf(String, Boolean, String, String)

    Exports a searchable PDF version of the OCR input document as a byte array. Works for all input formats including PDFs & Images.

    Declaration
    public byte[] SaveAsSearchablePdf(string Path = null, bool ApplyFilters = false, string CustomFontFile = null, string CustomFontName = null)
    Parameters
    Type Name Description
    System.String Path

    The file path the PDF will be saved to.

    System.Boolean ApplyFilters

    Determine whether applying OcrFilters to the output searchable pdf or not; default is false.

    System.String CustomFontFile

    Optional path to a custom font file (.ttf, .otf) for rendering text in the PDF. Required for proper UTF-8 character support in languages like Polish, Arabic, Chinese, etc.

    System.String CustomFontName

    Optional custom font name. If not provided, will be extracted from the font file.

    Returns
    Type Description
    System.Byte[]

    SaveAsSearchablePdfBytes(Boolean, String, String)

    Exports a searchable PDF version of the OCR input document as a byte array. Works for all input formats including PDFs & Images.

    Declaration
    public byte[] SaveAsSearchablePdfBytes(bool ApplyFilters = false, string CustomFontFile = null, string CustomFontName = null)
    Parameters
    Type Name Description
    System.Boolean ApplyFilters

    Determine whether applying OcrFilters to the output searchable pdf or not; default is false.

    System.String CustomFontFile

    Optional path to a custom font file (.ttf, .otf) for rendering text in the PDF. Required for proper UTF-8 character support in languages like Polish, Arabic, Chinese, etc.

    System.String CustomFontName

    Optional custom font name. If not provided, will be extracted from the font file.

    Returns
    Type Description
    System.Byte[]

    SaveAsSearchablePdfStream(Boolean, String, String)

    Exports a searchable PDF version of the OCR input document as a Stream. Works for all input formats including PDFs & Images.

    Declaration
    public Stream SaveAsSearchablePdfStream(bool ApplyFilters = false, string CustomFontFile = null, string CustomFontName = null)
    Parameters
    Type Name Description
    System.Boolean ApplyFilters

    Determine whether applying OcrFilters to the output searchable pdf or not; default is false.

    System.String CustomFontFile

    Optional path to a custom font file (.ttf, .otf) for rendering text in the PDF.

    System.String CustomFontName

    Optional custom font name. If not provided, will be extracted from the font file.

    Returns
    Type Description
    System.IO.Stream

    SaveAsTextFile(String)

    Exports a .txt version of the Tesseract results objects document. This is a plain text file.

    4 Environment.Newlines between pages. 2 Environment.Newlines between paragraphs.

    Declaration
    public void SaveAsTextFile(string Path)
    Parameters
    Type Name Description
    System.String Path

    The file path the text file will be saved to.

    SaveJsonAs(String)

    Serializes the OcrResult object to a JSON file..

    Declaration
    public void SaveJsonAs(string Path)
    Parameters
    Type Name Description
    System.String Path
    Remarks

    Use the method ToJson() instead if you want to get the string instead of saving to disk.

    ToJson()

    Serializes the OcrResult object to a JSON string.

    Declaration
    public string ToJson()
    Returns
    Type Description
    System.String

    The JSON string representation of the OcrResult.

    Remarks

    Use the method FromJson(String) for deserializing the JSON to the OcrResult object.

    Implements

    IronSoftware.Abstractions.Ocr.IOcrResult
    IronSoftware.Abstractions.Absolute.IDocumentPageContainer<>
    IronSoftware.Abstractions.Pdf.IDocumentWithExtractableText
    ☀
    ☾
    Downloads
    • Download with Nuget
    • Start for Free
    In This Article
    Back to top
    Install with Nuget