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.
How to Highlight Texts As Images
- Download a C# library to detect page rotation
- Instantiate OCR engine
- Load the PDF document with
LoadPdf
- Using
HighlightTextAndSaveAsImages
highlight section of text and save them as images
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.
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)
Output Images

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.