Highlight Texts As Images

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.

Get started with IronOCR

Start using IronOCR in your project today with a free trial.

First Step:
green 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.

Please noteThis 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.

Curtis Chau
Technical Writer

Curtis Chau holds a Bachelor’s degree in Computer Science (Carleton University) and specializes in front-end development with expertise in Node.js, TypeScript, JavaScript, and React. Passionate about crafting intuitive and aesthetically pleasing user interfaces, Curtis enjoys working with modern frameworks and creating well-structured, visually appealing manuals.

...Read More

Ready to Get Started?
Nuget Downloads 4,685,233 | Version: 2025.10 just released