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.
Quickstart: Highlight Text in Images with IronOCR
Easily highlight text within images using IronOCR's powerful tools. This quickstart guide shows you how to utilize the HighlightTextAndSaveAsImages method to visually inspect OCR results. By following the steps provided, you can efficiently highlight paragraphs in a PDF and save the output as images. This method ensures that the OCR engine accurately identifies and processes text, offering an easy get-started experience for developers.
Get started making PDFs with NuGet now:
Install IronPDF with NuGet Package Manager
Copy and run this code snippet.
var Ocr = new IronSoftware.IronOcr.IronTesseract(); using (var Input = new IronSoftware.IronOcr.OcrInput("input.pdf")) { Ocr.Read(Input).HighlightTextAndSaveAsImages("output", IronSoftware.IronOcr.ResultHighlightType.Paragraph); }Deploy to test on your live environment
Minimal Workflow (5 steps)
- Download a C# library to detect page rotation
- Instantiate OCR engine
- Load the PDF document with
LoadPdf - Using
HighlightTextAndSaveAsImageshighlight 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.csusing 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.
Frequently Asked Questions
What is the purpose of highlighting texts as images in IronOCR?
Highlighting texts as images in IronOCR is used to visualize OCR results by rendering bounding boxes around detected text elements in an image. This process helps in debugging and validating the accuracy of OCR output by providing a clear map of recognized content.
How does IronOCR's HighlightTextAndSaveAsImages method work?
The HighlightTextAndSaveAsImages method in IronOCR allows developers to highlight specific sections of text and save them as images. It takes three parameters: the IronTesseract OCR engine, a prefix for the output filename, and a ResultHighlightType enum that specifies the type of text to highlight.
What are the available highlighting types in IronOCR?
IronOCR offers four highlighting types through the ResultHighlightType enum: Character, Word, Line, and Paragraph. Each type provides a different level of detail, ranging from individual characters to entire paragraphs.
Can IronOCR highlight text in PDF documents?
Yes, IronOCR can highlight text in PDF documents. You can load a PDF with the LoadPdf method and use HighlightTextAndSaveAsImages to highlight specific sections of text and save them as images.
What is the benefit of using the Paragraph highlight type in IronOCR?
The Paragraph highlight type in IronOCR provides a higher-level view of the document structure by highlighting entire blocks of text grouped as paragraphs. This is useful for visualizing the flow and organization of text within a document.
How can developers start using IronOCR for text highlighting?
Developers can start using IronOCR for text highlighting by downloading a C# library, instantiating the OCR engine, loading a PDF document using LoadPdf, and then applying the HighlightTextAndSaveAsImages method to highlight and save text sections as images.
What code example is provided for highlighting text as images in IronOCR?
The web page provides a C# code example demonstrating how to load a PDF with LoadPdf, apply the HighlightTextAndSaveAsImages method, and save the highlighted text as images using the ResultHighlightType.Paragraph option.




