How to Extract Read Results

This article was translated from English: Does it need improvement?
Translated
View the article in English

The read or OCR result encompasses a wealth of information pertaining to detected paragraphs, lines, words, and individual characters. For each of these elements, the result provides a comprehensive set of details.

For each element, it provides the text content, precise X and Y coordinates, dimensions (width and height), text direction (Left to Right or Top to Bottom), and location in a CropRectangle object.

Quickstart: Retrieve Word Text from First Detected Word

Get started in seconds: use IronTesseract’s Read method to OCR an image and pull the first word’s text using the Words collection. Perfect for fast setups and simple extraction tasks.

Nuget IconGet started making PDFs with NuGet now:

  1. Install IronOCR with NuGet Package Manager

    PM > Install-Package IronOcr

  2. Copy and run this code snippet.

    string wordText = new IronTesseract().Read("file.jpg").Words[0].Text;
  3. Deploy to test on your live environment

    Start using IronOCR in your project today with a free trial
    arrow pointer

Data Output

The result value doesn't only contain the extracted text but also provides information about pages, paragraphs, lines, words, characters, and barcodes discovered in the PDF and image document by IronOcr. You can access this information from the returned OcrResult object using the Read method.

:path=/static-assets/ocr/content-code-examples/how-to/read-results-output-information.cs
using IronOcr;
using System;
using static IronOcr.OcrResult;

// Instantiate IronTesseract
IronTesseract ocrTesseract = new IronTesseract();

// Add image
using var imageInput = new OcrImageInput("sample.jpg");
// Perform OCR
OcrResult ocrResult = ocrTesseract.Read(imageInput);

// Retrieve list of detected paragraphs
Paragraph[] paragraphs = ocrResult.Paragraphs;

// Output information to console
Console.WriteLine($"Text: {paragraphs[0].Text}");
Console.WriteLine($"X: {paragraphs[0].X}");
Console.WriteLine($"Y: {paragraphs[0].Y}");
Console.WriteLine($"Width: {paragraphs[0].Width}");
Console.WriteLine($"Height: {paragraphs[0].Height}");
Console.WriteLine($"Text direction: {paragraphs[0].TextDirection}");
Imports IronOcr
Imports System
Imports IronOcr.OcrResult

' Instantiate IronTesseract
Private ocrTesseract As New IronTesseract()

' Add image
Private imageInput = New OcrImageInput("sample.jpg")
' Perform OCR
Private ocrResult As OcrResult = ocrTesseract.Read(imageInput)

' Retrieve list of detected paragraphs
Private paragraphs() As Paragraph = ocrResult.Paragraphs

' Output information to console
Console.WriteLine($"Text: {paragraphs(0).Text}")
Console.WriteLine($"X: {paragraphs(0).X}")
Console.WriteLine($"Y: {paragraphs(0).Y}")
Console.WriteLine($"Width: {paragraphs(0).Width}")
Console.WriteLine($"Height: {paragraphs(0).Height}")
Console.WriteLine($"Text direction: {paragraphs(0).TextDirection}")
$vbLabelText   $csharpLabel
Data in OcrResult

Text in OCR Result

The OcrResult object presents the extracted text in a simple, intuitive way, allowing developers to use it as is or integrate it into other parts of their application.

Let's look at the code example that prints the text in a loop to verify the results.

:path=/static-assets/ocr/content-code-examples/how-to/read-results-output-text.cs
using IronOcr;
using System;
using static IronOcr.OcrResult;

// Instantiate IronTesseract
IronTesseract ocrTesseract = new IronTesseract();

// Add image
using var imageInput = new OcrImageInput("sampleText.png");
// Perform OCR
OcrResult ocrResult = ocrTesseract.Read(imageInput);

// Retrieve list of detected paragraphs
Paragraph[] paragraphs = ocrResult.Paragraphs;

// Loop through each paragraph in the array
Console.WriteLine("--- All Detected Paragraphs ---");
foreach (Paragraph paragraph in paragraphs)
{
    // Print the text of the current paragraph
    Console.WriteLine(paragraph.Text);
    
    // Add a blank line for better separation (optional)
    Console.WriteLine(); 
}

IRON VB CONVERTER ERROR developers@ironsoftware.com
$vbLabelText   $csharpLabel

Output

Text data in OcrResult

Here's the output printed to the console. As you can see, IronOCR perfectly extracts the paragraph text, line by line, with precision.

Text Location in OCR Result

In addition to the extracted text, the OcrResult provides detailed location data. The following code demonstrates how to iterate over each paragraph and print its coordinates (X and Y) to the console.

:path=/static-assets/ocr/content-code-examples/how-to/read-results-output-coordinates.cs
using IronOcr;
using System;
using static IronOcr.OcrResult;

// Instantiate IronTesseract
IronTesseract ocrTesseract = new IronTesseract();

// Add image
using var imageInput = new OcrImageInput("sampleText.png");
// Perform OCR
OcrResult ocrResult = ocrTesseract.Read(imageInput);

// Retrieve list of detected paragraphs
Paragraph[] paragraphs = ocrResult.Paragraphs;

Console.WriteLine("--- All Detected Coordinates of Paragraphs ---");

// Use a 'for' loop to get an index for each paragraph
for (int i = 0; i < paragraphs.Length; i++)
{
    // Get the current paragraph
    Paragraph paragraph = paragraphs[i];

    // Print the paragraph number, text, and its location
    Console.WriteLine($"X: {paragraph.X}"); // X-coordinate (left edge)
    Console.WriteLine($"Y: {paragraph.Y}"); // Y-coordinate (top edge)

    // Add a blank line for better separation
    Console.WriteLine();
}
IRON VB CONVERTER ERROR developers@ironsoftware.com
$vbLabelText   $csharpLabel

Output

Text coordinates in OcrResult

As you can see from the output, you see three sets of coordinates corresponding to the three paragraphs.

Additional Attributes in OCR Result

Aside from the text and text coordinates, IronOCR offers additional information. For each part of the text, like paragraphs, lines, words, and individual characters, we provide the following information:

  • Text: The actual text as a string.
  • X: The position from the left edge of the page in pixels.
  • Y: The position from the top edge of the page in pixels.
  • Width: The width in pixels.
  • Height: The height in pixels.
  • Text Direction: The direction in which the text was read, like 'Left to Right' or 'Top to Bottom.'
  • Location: A rectangle showing where this text is on the page in pixels.

Paragraph, Line, Word, and Character Comparison

Below is the comparison of the detected paragraphs, lines, words, and characters.

Highlight paragraph
Highlight line
Highlight word
Highlight character

Barcode and QR Code

That’s correct! IronOcr can read barcodes and QR codes. While the feature may not be as robust as IronBarcode, IronOcr does provide support for common barcode types. To enable barcode detection, set the Configuration.ReadBarCodes property to true.

Additionally, valuable information can be extracted from the detected barcode, including its format, value, coordinates (x, y), height, width, and location as IronSoftware.Drawing.Rectangle object. This Rectangle class in IronDrawing allows for precise positioning on the document.

:path=/static-assets/ocr/content-code-examples/how-to/read-results-barcodes.cs
using IronOcr;
using System;
using static IronOcr.OcrResult;

// Instantiate IronTesseract
IronTesseract ocrTesseract = new IronTesseract();

// Enable barcodes detection
ocrTesseract.Configuration.ReadBarCodes = true;

// Add image
using OcrInput ocrInput = new OcrInput();
ocrInput.LoadPdf("sample.pdf");

// Perform OCR
OcrResult ocrResult = ocrTesseract.Read(ocrInput);

// Output information to console
foreach(var barcode in ocrResult.Barcodes)
{
    Console.WriteLine("Format = " + barcode.Format);
    Console.WriteLine("Value = " + barcode.Value);
    Console.WriteLine("X = " + barcode.X);
    Console.WriteLine("Y = " + barcode.Y);
}
Console.WriteLine(ocrResult.Text);
Imports IronOcr
Imports System
Imports IronOcr.OcrResult

' Instantiate IronTesseract
Private ocrTesseract As New IronTesseract()

' Enable barcodes detection
ocrTesseract.Configuration.ReadBarCodes = True

' Add image
Using ocrInput As New OcrInput()
	ocrInput.LoadPdf("sample.pdf")
	
	' Perform OCR
	Dim ocrResult As OcrResult = ocrTesseract.Read(ocrInput)
	
	' Output information to console
	For Each barcode In ocrResult.Barcodes
		Console.WriteLine("Format = " & barcode.Format)
		Console.WriteLine("Value = " & barcode.Value)
		Console.WriteLine("X = " & barcode.X)
		Console.WriteLine("Y = " & barcode.Y)
	Next barcode
	Console.WriteLine(ocrResult.Text)
End Using
$vbLabelText   $csharpLabel

Output

Detect barcodes

Preguntas Frecuentes

¿Cómo extraigo elementos de texto de imágenes y PDFs usando C#?

Puedes extraer elementos de texto de imágenes y PDFs usando IronOCR, utilizando su método `Read`, que realiza Reconocimiento Óptico de Caracteres (OCR) para obtener detalles sobre párrafos, líneas, palabras y caracteres, incluyendo su contenido de texto, coordenadas y dimensiones.

¿Cuál es el proceso para comenzar con OCR en .NET C#?

Para comenzar con OCR en .NET C#, descarga la biblioteca IronOCR desde NuGet, prepara tu imagen o documento PDF y usa el método `Read` para obtener un objeto `OcrResult`, que contiene información detallada sobre el texto extraído y la estructura del documento.

¿Puede IronOCR detectar y extraer información de códigos de barras?

Sí, IronOCR puede detectar y extraer información de códigos de barras configurando la propiedad `Configuration.ReadBarCodes` a verdadero, permitiéndote recuperar datos como el formato del código de barras, su valor y su posición dentro del documento.

¿Qué tipos de elementos de documentos puede detectar IronOCR?

IronOCR puede detectar varios elementos de documentos incluyendo páginas, párrafos, líneas, palabras y caracteres individuales, así como códigos de barras y códigos QR, proporcionando un análisis exhaustivo de la estructura del documento.

¿Cómo puedo configurar IronOCR para leer texto en diferentes direcciones?

IronOCR es capaz de leer textos en múltiples direcciones, como 'Izquierda a Derecha' o 'Arriba a Abajo', analizando la propiedad de dirección dentro del objeto `OcrResult`.

¿Qué es el objeto `CropRectangle` en IronOCR?

El objeto `CropRectangle` en IronOCR define la ubicación y el tamaño de los elementos de texto en una página en términos de coordenadas y dimensiones, ayudando a la identificación y extracción precisa del texto.

¿Cómo uso el método `Read` de IronOCR para analizar documentos?

Para usar el método `Read` en IronOCR, crea una instancia del motor de IronOCR, carga tu documento de destino y ejecuta el método `Read` para obtener los resultados del OCR, que pueden usarse para acceder a los datos de texto y las propiedades del documento.

¿Cómo maneja IronOCR la detección de códigos QR?

IronOCR maneja la detección de códigos QR habilitando la lectura de códigos de barras a través del ajuste `Configuration.ReadBarCodes`, lo que permite extraer datos del código QR, incluyendo su formato, valor y ubicación.

¿Cuál es el papel de `OcrResult` en la extracción de texto?

El objeto `OcrResult` juega un papel crucial en la extracción de texto al contener el texto extraído y detalles acompañantes como la posición, dimensiones y dirección de los elementos de texto, así como información de códigos de barras.

¿Cómo puedo asegurar una extracción precisa de texto con IronOCR?

Para asegurar una extracción precisa de texto con IronOCR, asegúrate de proporcionar documentos de entrada de alta calidad y configurar adecuadamente los ajustes como `Configuration.ReadBarCodes` para la detección de códigos de barras, optimizando el rendimiento del OCR.

Chaknith Bin
Ingeniero de Software
Chaknith trabaja en IronXL e IronBarcode. Tiene un profundo conocimiento en C# y .NET, ayudando a mejorar el software y apoyar a los clientes. Sus conocimientos derivados de las interacciones con los usuarios contribuyen a mejores productos, documentación y experiencia en general.
¿Listo para empezar?
Nuget Descargas 5,044,537 | Versión: 2025.11 recién lanzado