Once an OCR engine has pulled the text out of a scanned page, the typography is gone. You know what the document says, but not whether a heading was set in bold 18-point type or whether a form field used the same font as the rest of the page. Rebuilding a document’s layout, checking that a printed form follows brand guidelines, or sorting documents by their visual style all need that missing information.

Aspose.OCR for .NET closes that gap with font detection. When you enable it, every recognized line comes back with its font family, style, size and a confidence score, alongside the text and its bounding box.

This article shows how to turn font detection on, walks through the result properties one by one, extends the example to a folder of images with CSV export, and sets out what the feature can and cannot do.

Key Takeaways

  • Aspose.OCR for .NET returns the font family, style, pixel height, estimated point size and confidence scores for each recognized line.
  • You enable it by setting a single flag in the recognition settings; the font data then hangs off each line result.
  • Font detection is designed for printed text. Handwriting and decorative type return low confidence and may fall back to a generic family.
  • The confidence values are engine scores, not calibrated probabilities. Pick a review threshold that suits your input quality and workflow.
  • Point size is an estimate and can be null; the pixel height is always present.

New to the library? The C# OCR library product page covers formats, languages and platform support before you write any code.

What font details can Aspose.OCR return from OCR results?

For every non-empty line, Aspose.OCR returns a FontLineResult object with six pieces of typographic data plus a line index. It describes the line as a whole, not individual words or characters.

PropertyTypeWhat it holds
FontstringDetected font family name, for example Arial.
FontConfidencedoubleConfidence score for the family, 0–1.
StylestringDetected style: regular, italic, or bold_italic.
StyleConfidencedoubleConfidence score for the style, 0–1.
SizePxdoubleLine height in pixels, measured from the image.
SizePtEstimatedouble?Estimated font size in points. Can be null.
LineIndexintZero-based index of the line in the processed batch.

API behavior: the property names, types and the documented style values above come from the Aspose.OCR for .NET API reference for FontLineResult and the font detection guide.

What do you need to detect fonts with Aspose.OCR for .NET?

You need the 26.7 package, a printed-text raster image, and a few lines of setup. Font detection was introduced in Aspose.OCR for .NET 26.7, so an older package will not compile against this code.

  • Aspose.OCR for .NET 26.7 or later, added to your project from NuGet.
  • A .NET project. Aspose.OCR ships for both .NET Framework and modern .NET; use whichever your solution already targets. The examples here were run on .NET 10.
  • Room for the font model. The first recognition call with DetectFonts enabled downloads a font-analysis model (about 686 MB in the 26.7 build) into the working directory. It is fetched once and reused; later runs start in seconds.
  • An input image such as PNG, JPEG or TIFF containing printed text. Photographed pages work; the cleaner the scan, the higher the confidence.
  • A license. Without one the engine runs in evaluation mode, which truncates recognition output — in testing it returned only the first line of a multi-line image and clipped the first character. Use the free temporary license (covered below) for representative results.
Install-Package Aspose.OCR

Confirm the installed package is 26.7.0 or later, since that is the release that added font detection.

How do you extract font details from OCR results in .NET?

Set DetectFonts to true in RecognitionSettings, run recognition, and read the Font property of each line in RecognitionLinesResult. The font data is populated only when DetectFonts is enabled.

Input:    source.png (raster image with printed text)
Output:   font family, style, size and confidence per recognized line
Library:  Aspose.OCR for .NET 26.7
Language: C#

The sample below is the reference example from the Aspose.OCR for .NET 26.7 release notes. It was compiled and run against Aspose.OCR for .NET 26.7.0 on .NET 10: it produced regular for the style, a double pixel size, and a populated point-size estimate, with the two confidence values in the 0–1 range.

using Aspose.OCR;
using System;
using System.Linq;

// Initialize the OCR engine.
AsposeOcr recognitionEngine = new AsposeOcr();

// Prepare the input image. Replace "source.png" with your file path.
OcrInput input = new OcrInput(InputType.SingleImage);
input.Add("source.png");

// Turn on font detection.
RecognitionSettings settings = new RecognitionSettings
{
    DetectFonts = true,   // Populates FontLineResult on each recognized line
    ThreadsCount = 1       // 0 (default) uses one thread per processor
};

// Recognize returns an OcrOutput, which is a List<RecognitionResult>.
RecognitionResult result = recognitionEngine.Recognize(input, settings)[0];

// Read the font details for every line that actually contains text.
foreach (RecognitionResult.LinesResult line in result.RecognitionLinesResult
    .Where(line => !string.IsNullOrWhiteSpace(line.TextInLine)))
{
    FontLineResult font = line.Font;

    Console.WriteLine(line.TextInLine);
    Console.WriteLine($"Font: {font.Font} ({font.FontConfidence:P0})");
    Console.WriteLine($"Style: {font.Style} ({font.StyleConfidence:P0})");
    Console.WriteLine($"Size: {font.SizePx}px / {font.SizePtEstimate}pt");
}

For each recognized line, the console shows the text followed by three font lines. This is the actual output for one line of a test image rendered in a sans-serif face:

Invoice Number 10428
Font: Segoe UI (98%)
Style: regular (97%)
Size: 26px / 6.24pt

The family name reflects the closest face the engine matched, so it tracks the rendered font rather than any label in the source. {font.SizePtEstimate} prints nothing when the estimate is null, so a line with no estimate reads Size: 26px / pt. Under evaluation mode the engine returns only part of the text — typically the first line — so run with a license to see every line.

What does each part of the code do?

Each call moves the image one step closer to structured font data.

  1. new AsposeOcr() creates the recognition engine. The class lives in the Aspose.OCR namespace. A license unlocks full functionality; without one the engine runs in evaluation mode.
  2. new OcrInput(InputType.SingleImage) creates the input container and tells the engine the source is a stand-alone raster image. input.Add("source.png") adds the file; you can add more than one to process a batch in a single call.
  3. new RecognitionSettings { DetectFonts = true, ThreadsCount = 1 } configures recognition. DetectFonts = true is what makes the engine analyze glyphs and populate FontLineResult. ThreadsCount controls parallelism: 0, the default, uses one thread per processor; 1 forces single-threaded execution, which keeps output easier to follow while debugging.
  4. recognitionEngine.Recognize(input, settings) runs OCR and returns an OcrOutput. OcrOutput derives from List<RecognitionResult>, so [0] is the result for the first image.
  5. result.RecognitionLinesResult is the list of RecognitionResult.LinesResult objects, one per detected line. The Where filter drops lines whose TextInLine is empty or whitespace, which can occur on image noise.
  6. line.Font returns the FontLineResult for that line. It is filled only because DetectFonts was enabled; with the flag off it is not populated.

The font detection guide and the 26.7 release notes are the primary references for this feature if you need to check behavior against your version.

What does each FontLineResult property mean?

FontLineResult mixes measured values with estimates and scores, so it helps to know which is which before you build logic on top of it.

  • Font — API behavior. The detected font family name, such as Arial or Times New Roman. Aspose.OCR recognizes common printed faces; an unrecognized face resolves to the closest match the engine knows.
  • FontConfidence — API behavior. A 0–1 confidence score for the family. The documentation does not define it as a calibrated probability, so read it as a relative signal: higher means the engine is surer.
  • Style — API behavior. One of regular, italic, or bold_italic.
  • StyleConfidence — API behavior. A 0–1 confidence score for the style, read the same way as FontConfidence.
  • SizePx — API behavior. The line height in pixels, measured from the image. Always present.
  • SizePtEstimate — API behavior. An estimated point size, typed as double?. It can be null, so check before formatting or converting it.
  • LineIndex — API behavior. The zero-based position of the line in the processed batch, useful for correlating font data with other per-line results.

How do you handle low-confidence or unknown font results?

Branch on the confidence scores and treat anything below your chosen threshold as “needs review” rather than a fact. There is no official cut-off; the right value depends on your scans and how costly a wrong classification is.

  • Set an application threshold. Example heuristic: an internal tool might flag any line where FontConfidence or StyleConfidence is below 0.5 for a human to check. A batch pipeline over clean, high-resolution scans could safely use a lower bar; noisy phone photos may need a higher one. Measure against your own document set.
  • Improve the input. Low confidence often means the glyph metrics were unclear. A higher-resolution scan, or pre-processing to deskew and denoise the image before recognition, usually raises the scores.
  • Expect weak results on handwriting. API behavior: font detection is tuned for printed type. Handwritten notes, stylized logos and display lettering commonly come back with low confidence and a generic family. Check FontConfidence before you display or store the family for these documents.
  • Guard against a null point size. SizePtEstimate is nullable. Fall back to SizePx or skip the field when it is null.
  • Know the temporary-license behavior. API behavior: the line-level Confidence on RecognitionResult.LinesResult returns 0 under a temporary license and is only calculated for certain language groups. This is the line’s text confidence, separate from the font confidence scores, but it catches people out during evaluation.

How do you extract font details from many images at once?

Loop over the files in a folder, run recognition per file inside a try/catch, and write one CSV row per line with the values properly escaped. Isolating each file means one unreadable image does not stop the batch.

using Aspose.OCR;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;

class FontBatch
{
    static void Main()
    {
        string folder = @"C:\ScannedDocs";
        string reportPath = Path.Combine(folder, "font_report.csv");

        AsposeOcr recognitionEngine = new AsposeOcr();
        RecognitionSettings settings = new RecognitionSettings { DetectFonts = true };

        var csv = new List<string>
        {
            "File,LineIndex,Text,Font,FontConfidence,Style,StyleConfidence,SizePx,SizePtEstimate"
        };

        foreach (string file in Directory.GetFiles(folder, "*.png"))
        {
            try
            {
                OcrInput input = new OcrInput(InputType.SingleImage);
                input.Add(file);

                RecognitionResult result = recognitionEngine.Recognize(input, settings)[0];

                foreach (RecognitionResult.LinesResult line in result.RecognitionLinesResult
                    .Where(l => !string.IsNullOrWhiteSpace(l.TextInLine)))
                {
                    FontLineResult font = line.Font;
                    if (font == null)
                    {
                        continue;
                    }

                    string pt = font.SizePtEstimate.HasValue
                        ? font.SizePtEstimate.Value.ToString("F1", CultureInfo.InvariantCulture)
                        : string.Empty;

                    csv.Add(string.Join(",",
                        Csv(Path.GetFileName(file)),
                        font.LineIndex.ToString(CultureInfo.InvariantCulture),
                        Csv(line.TextInLine),
                        Csv(font.Font),
                        font.FontConfidence.ToString("F3", CultureInfo.InvariantCulture),
                        Csv(font.Style),
                        font.StyleConfidence.ToString("F3", CultureInfo.InvariantCulture),
                        font.SizePx.ToString("F1", CultureInfo.InvariantCulture),
                        pt));
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Skipped {Path.GetFileName(file)}: {ex.Message}");
            }
        }

        File.WriteAllLines(reportPath, csv);
        Console.WriteLine($"Wrote {csv.Count - 1} rows to {reportPath}");
    }

    // Wrap a field in quotes and double any embedded quotes if it contains
    // a comma, quote, or line break, per RFC 4180.
    static string Csv(string value)
    {
        if (string.IsNullOrEmpty(value))
        {
            return string.Empty;
        }

        if (value.IndexOfAny(new[] { ',', '"', '\n', '\r' }) >= 0)
        {
            return "\"" + value.Replace("\"", "\"\"") + "\"";
        }

        return value;
    }
}

This runs on Aspose.OCR 26.7.0: it writes font_report.csv with one row per recognized line, and recognized text containing commas or quotes is escaped so the file opens cleanly in Excel or Power BI.

What are the limitations of OCR font detection?

Font detection is a practical estimate of typography, not a font-forensics tool. Keep these boundaries in mind when you design around it.

  • It is line-level. API behavior: one FontLineResult describes an entire recognized line. A line that mixes two fonts or sizes is summarized as one result.
  • The family is a best match. Aspose.OCR recognizes common printed faces. A face it does not know is reported as the nearest one it does.
  • The style set is small. Only regular, italic, and bold_italic are reported. There is no separate “bold” or weight scale in the result.
  • Point size is estimated. SizePtEstimate is derived by the engine and can be null. SizePx is the only size value that is always measured.
  • Confidence scores are not probabilities. They rank certainty relative to each other; they are not documented as calibrated.
  • Printed text only. Handwriting and decorative scripts are out of scope and return low confidence.
  • PDF pages go through the same path. Create the OcrInput with InputType.PDF; each page produces its own RecognitionResult and its own set of line-level font data.
  • The first run is slow. Enabling DetectFonts downloads a large model (about 686 MB in 26.7) before the first recognition completes. Warm it up once during deployment rather than on a user’s first request; after that, added overhead per image is small.

How do you get a free Aspose.OCR license?

Aspose issues a free 30-day temporary license that lets you evaluate the API without evaluation-mode limits. Request one from the temporary license page and load it before you create the engine.

Detect Font Details Online - Aspose Font Detector

Want to identify the font used in an image without writing code? Try the free Aspose Font Detector  online tool. Upload an image containing printed text, and the tool can analyze the text to identify font-related details such as the font family, style, and size.

Image

This is useful for checking scanned documents, matching typography in designs, validating brand guidelines, or identifying fonts before recreating a document. The online tool is also a convenient way to explore font detection before integrating the same capability into an application with Aspose.OCR for .NET.

Conclusion

Font detection in Aspose.OCR for .NET 26.7 turns a flag and gives you the font family, style, size and confidence for every recognized line. Read SizePx as measured and SizePtEstimate as an estimate, treat the confidence scores as relative signals with a threshold you choose, and keep the feature pointed at printed text. From there the batch pattern above scales the same logic across an entire archive.

Start with the Aspose.OCR for .NET font detection guide and the RecognitionSettings reference for the full set of recognition options.

FAQs

  1. Which Aspose.OCR for .NET version is required for font detection? Font detection was added in Aspose.OCR for .NET 26.7 (July 2026). Earlier versions do not expose the DetectFonts setting or the FontLineResult type, so upgrade to 26.7 or later.
  2. Can I extract font information from multi-page PDFs? Yes. Create the OcrInput with InputType.PDF and add the PDF file; each page is recognized separately and returns its own RecognitionResult. You can also rasterize pages to images first and run the single-image flow.
  3. What does the FontConfidence value represent? FontConfidence is the engine’s confidence score for the detected font family, in the 0–1 range. The documentation does not define it as a calibrated probability, so treat it as a relative indicator and choose your own threshold for review.
  4. Is the detected font size exact? SizePx (the line height in pixels) is measured directly. SizePtEstimate is an estimate in points and can be null, so always guard against a missing value before formatting it.
  5. Does font detection work on handwritten text? It is built for printed text with consistent glyph metrics. Handwritten and decorative scripts usually return low confidence and may resolve to a generic family, so branch on FontConfidence before you trust the result.

Read More