Class AdvancedOcrResultBase
Base class for advanced OCR results that support searchable PDF generation
Implements
Namespace: IronOcr
Assembly: IronOcr.dll
Syntax
public abstract class AdvancedOcrResultBase : Object, IOcrResult
Constructors
AdvancedOcrResultBase()
Declaration
protected AdvancedOcrResultBase()
Properties
Confidence
OCR statistical accuracy confidence as an average of every character.
1 = 100%, 0 = 0%.
Declaration
public abstract double Confidence { get; }
Property Value
| Type | Description |
|---|---|
| System.Double |
Text
All OCR texts from OcrInput.
Declaration
public abstract string Text { get; }
Property Value
| Type | Description |
|---|---|
| System.String |
Methods
SaveAsSearchablePdf(String, Boolean, String, String)
Exports the OCR result as a searchable PDF document and optionally saves it to a file.
A searchable PDF overlays invisible OCR text on the original image, allowing text selection and search while preserving the original appearance.
------------------------------------------------
Usage:
// Load OCR input
var input = new IronOcr.OcrInput();
input.LoadPdf("scanned.pdf");
// Instantiate OCR engine and enable searchable PDF rendering
var ocr = new IronOcr.IronTesseract();
ocr.Configuration.RenderSearchablePdf = true;
// Read the document
var result = ocr.ReadPhoto(input);
// Export and save as searchable PDF
byte[] pdfBytes = result.SaveAsSearchablePdf("output.pdf");
// Or with custom font for UTF-8 support (e.g., for Polish text)
byte[] pdfBytes = result.SaveAsSearchablePdf(
Path: "output.pdf",
ApplyFilters: false,
CustomFontFile: @"C:\Fonts\DejaVuSans.ttf",
CustomFontName: "DejaVu Sans");
// The file is saved and bytes are also returned for further processing if needed
------------------------------------------------
Declaration
public byte[] SaveAsSearchablePdf(string Path = null, bool ApplyFilters = false, string CustomFontFile = null, string CustomFontName = null)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | Path | Optional. The file path where the PDF will be saved. If |
| System.Boolean | ApplyFilters | Optional. If |
| System.String | CustomFontFile | Optional. Path to a custom font file (.ttf, .otf, .ttc) to use for rendering text in the PDF. Useful for languages requiring full UTF-8 support (e.g., Polish, Arabic, Chinese). If not specified, the default TimesNewRoman font is used. |
| System.String | CustomFontName | Optional. Name of the custom font. If not provided, the font name will be automatically extracted from the font file metadata.
This parameter is only used when |
Returns
| Type | Description |
|---|---|
| System.Byte[] | A byte array containing the searchable PDF document. |
Remarks
Important Considerations:
Configuration Required: You must set IronTesseract.Configuration.RenderSearchablePdf = true before reading the document, otherwise this method will throw an exception.
Performance: The PDF bytes are cached after first generation, so subsequent calls return immediately without regenerating.
Filters: Setting ApplyFilters to true applies image enhancement filters to improve PDF quality.
File Path Optional: If Path is null, the PDF is not saved to disk but the bytes are still returned.
Custom Fonts: Use CustomFontFile to provide a font with full UTF-8 support for languages like Polish, Arabic, Chinese, etc. The default TimesNewRoman has limited character support.
How-To Guide: Learn more about creating searchable PDFs
API Reference: See related searchable PDF methods
Exceptions
| Type | Condition |
|---|---|
| IronOcrProductException | Thrown when |
| IronOcrInputException | Thrown when the custom font file is invalid, inaccessible, or contains malicious content. |
SaveAsSearchablePdfBytes(Boolean, String, String)
Exports the OCR result as a searchable PDF document and returns it as a byte array.
A searchable PDF overlays invisible OCR text on the original image, allowing text selection and search while preserving the original appearance.
------------------------------------------------
Usage:
// Load OCR input
var input = new IronOcr.OcrInput();
input.LoadPdf("scanned.pdf");
// Instantiate OCR engine and enable searchable PDF rendering
var ocr = new IronOcr.IronTesseract();
ocr.Configuration.RenderSearchablePdf = true;
// Read the document
var result = ocr.ReadPhoto(input);
// Export as searchable PDF bytes
byte[] pdfBytes = result.SaveAsSearchablePdfBytes();
// Or with custom font for UTF-8 support
byte[] pdfBytes = result.SaveAsSearchablePdfBytes(
ApplyFilters: false,
CustomFontFile: @"C:\Fonts\DejaVuSans.ttf");
System.IO.File.WriteAllBytes("output.pdf", pdfBytes);
------------------------------------------------
Declaration
public byte[] SaveAsSearchablePdfBytes(bool ApplyFilters = false, string CustomFontFile = null, string CustomFontName = null)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Boolean | ApplyFilters | Optional. If |
| System.String | CustomFontFile | Optional. Path to a custom font file (.ttf, .otf, .ttc) to use for rendering text in the PDF. Useful for languages requiring full UTF-8 support (e.g., Polish, Arabic, Chinese). If not specified, the default TimesNewRoman font is used. |
| System.String | CustomFontName | Optional. Name of the custom font. If not provided, the font name will be automatically extracted from the font file metadata.
This parameter is only used when |
Returns
| Type | Description |
|---|---|
| System.Byte[] | A byte array containing the searchable PDF document. |
Remarks
Important Considerations:
Configuration Required: You must set IronTesseract.Configuration.RenderSearchablePdf = true before reading the document, otherwise this method will throw an exception.
Performance: The PDF bytes are cached after first generation, so subsequent calls return immediately without regenerating.
Filters: Setting ApplyFilters to true applies image enhancement filters to improve PDF quality.
Custom Fonts: Use CustomFontFile to provide a font with full UTF-8 support for languages like Polish, Arabic, Chinese, etc. The default TimesNewRoman has limited character support.
How-To Guide: Learn more about creating searchable PDFs
API Reference: See related searchable PDF methods
Exceptions
| Type | Condition |
|---|---|
| IronOcrProductException | Thrown when |
| IronOcrInputException | Thrown when the custom font file is invalid, inaccessible, or contains malicious content. |
SaveAsSearchablePdfStream(Boolean, String, String)
Exports the OCR result as a searchable PDF document and returns it as a Stream.
A searchable PDF overlays invisible OCR text on the original image, allowing text selection and search while preserving the original appearance.
------------------------------------------------
Usage:
// Load OCR input
var input = new IronOcr.OcrInput();
input.LoadPdf("scanned.pdf");
// Instantiate OCR engine and enable searchable PDF rendering
var ocr = new IronOcr.IronTesseract();
ocr.Configuration.RenderSearchablePdf = true;
// Read the document
var result = ocr.ReadPhoto(input);
// Export as searchable PDF stream
Stream pdfStream = result.SaveAsSearchablePdfStream();
// Or with custom font for UTF-8 support
Stream pdfStream = result.SaveAsSearchablePdfStream(
ApplyFilters: false,
CustomFontFile: @"C:\Fonts\DejaVuSans.ttf");
// Use the stream (e.g., send via HTTP response, save to database, etc.)
------------------------------------------------
Declaration
public Stream SaveAsSearchablePdfStream(bool ApplyFilters = false, string CustomFontFile = null, string CustomFontName = null)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Boolean | ApplyFilters | Optional. If |
| System.String | CustomFontFile | Optional. Path to a custom font file (.ttf, .otf, .ttc) to use for rendering text in the PDF. Useful for languages requiring full UTF-8 support (e.g., Polish, Arabic, Chinese). If not specified, the default TimesNewRoman font is used. |
| System.String | CustomFontName | Optional. Name of the custom font. If not provided, the font name will be automatically extracted from the font file metadata.
This parameter is only used when |
Returns
| Type | Description |
|---|---|
| System.IO.Stream | A Stream containing the searchable PDF document. |
Remarks
Important Considerations:
Configuration Required: You must set IronTesseract.Configuration.RenderSearchablePdf = true before reading the document, otherwise this method will throw an exception.
Performance: This method returns a new MemoryStream containing the cached PDF bytes, so subsequent calls create new streams but don't regenerate the PDF.
Filters: Setting ApplyFilters to true applies image enhancement filters to improve PDF quality.
Custom Fonts: Use CustomFontFile to provide a font with full UTF-8 support for languages like Polish, Arabic, Chinese, etc. The default TimesNewRoman has limited character support.
How-To Guide: Learn more about creating searchable PDFs
API Reference: See related searchable PDF methods
Exceptions
| Type | Condition |
|---|---|
| IronOcrProductException | Thrown when |
| IronOcrInputException | Thrown when the custom font file is invalid, inaccessible, or contains malicious content. |