Highlight Texts As Images

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

Visualizing OCR results involves rendering bounding boxes around the specific text elements that the engine has detected within an image. This process overlays distinct highlights on the exact locations of individual characters, words, lines, or paragraphs, providing a clear map of the recognized content.

This visual feedback is crucial for debugging and validating the accuracy of the OCR output, allowing developers to see what the software has identified and where it has made errors.

In this article, we'll demonstrate how IronOCR allows developers to perform diagnostics easily with its HighlightTextAndSaveAsImages method. This function enables developers to highlight specific sections of text and save them as images for verification.

Quickstart: Highlight Words in Your PDF Instantly

This snippet demonstrates how easy it is to use IronOCR: load a PDF and highlight each word in the document, saving the result as images. Just one line to get visual feedback on your OCR results and verify everything works smoothly.

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.

    new IronOcr.OcrInput().LoadPdf("document.pdf").HighlightTextAndSaveAsImages(new IronOcr.IronTesseract(), "highlight_page_", IronOcr.ResultHighlightType.Word);
  3. Deploy to test on your live environment

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

Highlight Text And Save As Images Example

Highlighting text and saving it as images is quite simple with IronOCR. In this example, we'll load an existing PDF with LoadPdf, then call the HighlightTextAndSaveAsImages method to highlight sections of the text and save them as images.

The method takes three parameters: the IronTesseract OCR engine, a prefix for the output filename, and an enum from ResultHighlightType that dictates the type of text to highlight. In this example, we'll use ResultHighlightType.Paragraph to highlight the text blocks as paragraphs.

Por favor notaThis function will use the output string prefix and append a page identifier (e.g., "page_0", "page_1") to the output image filename for each page.

We'll be using this example PDF with three paragraphs.

Input

Code

Let's take a look at the example code below.

:path=/static-assets/ocr/content-code-examples/how-to/highlight-texts-as-images.cs
using IronOcr;

IronTesseract ocrTesseract = new IronTesseract();

using var ocrInput = new OcrInput();
ocrInput.LoadPdf("document.pdf");
ocrInput.HighlightTextAndSaveAsImages(ocrTesseract, "highlight_page_", ResultHighlightType.Paragraph);
Imports IronOcr

Private ocrTesseract As New IronTesseract()

Private ocrInput = New OcrInput()
ocrInput.LoadPdf("document.pdf")
ocrInput.HighlightTextAndSaveAsImages(ocrTesseract, "highlight_page_", ResultHighlightType.Paragraph)
$vbLabelText   $csharpLabel

Output Images

Highlight text output

As you can see from the output image above, all three paragraphs have been highlighted with a light red box.

ResultHightLightType

In the example above, we used ResultHighlightType.Paragraph to highlight text blocks. IronOCR provides additional highlighting options through this enum. Below is a complete list of available types.

Character: This option provides the most detailed level of analysis by drawing a bounding box around every single character that the OCR engine detects, corresponding to each IronOcr.OcrResult.Character.

Word: When set to Word, the method highlights each complete word identified by the engine, which helps verify word segmentation and spacing from each word.

Line: This option highlights every single detected line with IronOCR, and highlights them as each text line.

Paragraph: For a higher-level view of the document structure, this option highlights entire blocks of text that the engine has grouped as a paragraph.

Preguntas Frecuentes

¿Cuál es el propósito de resaltar textos como imágenes en IronOCR?

Resaltar textos como imágenes en IronOCR se utiliza para visualizar los resultados de OCR al renderizar cajas delimitadoras alrededor de los elementos de texto detectados en una imagen. Este proceso ayuda a depurar y validar la precisión de la salida de OCR al proporcionar un mapa claro del contenido reconocido.

¿Cómo funciona el método HighlightTextAndSaveAsImages de IronOCR?

El método HighlightTextAndSaveAsImages en IronOCR permite a los desarrolladores resaltar secciones específicas de texto y guardarlas como imágenes. Toma tres parámetros: el motor OCR de IronTesseract, un prefijo para el nombre de archivo de salida y un enum ResultHighlightType que especifica el tipo de texto a resaltar.

¿Cuáles son los tipos de resaltado disponibles en IronOCR?

IronOCR ofrece cuatro tipos de resaltado a través del enum ResultHighlightType: Carácter, Palabra, Línea y Párrafo. Cada tipo proporciona un nivel diferente de detalle, que varía desde caracteres individuales hasta párrafos enteros.

¿Puede IronOCR resaltar texto en documentos PDF?

Sí, IronOCR puede resaltar texto en documentos PDF. Puede cargar un PDF con el método LoadPdf y usar HighlightTextAndSaveAsImages para resaltar secciones específicas de texto y guardarlas como imágenes.

¿Cuál es el beneficio de usar el tipo de resaltado de Párrafo en IronOCR?

El tipo de resaltado de Párrafo en IronOCR proporciona una vista de mayor nivel de la estructura del documento al resaltar bloques enteros de texto agrupados como párrafos. Esto es útil para visualizar el flujo y la organización del texto dentro de un documento.

¿Cómo pueden los desarrolladores comenzar a usar IronOCR para resaltar texto?

Los desarrolladores pueden comenzar a usar IronOCR para resaltar texto descargando una biblioteca C#, instanciando el motor OCR, cargando un documento PDF usando LoadPdf y luego aplicando el método HighlightTextAndSaveAsImages para resaltar y guardar secciones de texto como imágenes.

¿Qué ejemplo de código se proporciona para resaltar texto como imágenes en IronOCR?

La página web proporciona un ejemplo de código C# que demuestra cómo cargar un PDF con LoadPdf, aplicar el método HighlightTextAndSaveAsImages y guardar el texto resaltado como imágenes utilizando la opción ResultHighlightType.Paragraph.

Curtis Chau
Escritor Técnico

Curtis Chau tiene una licenciatura en Ciencias de la Computación (Carleton University) y se especializa en el desarrollo front-end con experiencia en Node.js, TypeScript, JavaScript y React. Apasionado por crear interfaces de usuario intuitivas y estéticamente agradables, disfruta trabajando con frameworks modernos y creando manuales bien ...

Leer más
¿Listo para empezar?
Nuget Descargas 5,044,537 | Versión: 2025.11 recién lanzado