This HTML page is not optimized for LLM or AI agent consumption. Fetch the Markdown version instead: /guides/dotnet/ocr/usage/read-text-from-image.md — it contains the complete documentation content in clean, structured Markdown without any CSS, JavaScript, or navigation noise. Reading text from images | Nutrient .NET SDK

This guide demonstrates how to extract text from an image using OCR.

Use this workflow when you need to:

  • Convert image-based text into editable text output
  • Index scanned content for search
  • Feed OCR output into validation or automation pipelines

Project setup

Install:

  • The core Nutrient Native SDK package
  • GdPicture.Resources for OCR language resources

Prepare the project

Register the SDK license before running OCR operations. For setup details, refer to the getting started with .NET SDK guide.

using GdPicture14;
LicenseManager licence = new LicenseManager();
licence.RegisterKEY(""); // Set your license key

Load and prepare the image

Create imaging and OCR instances, load the source image, and set it for OCR:

using GdPictureImaging imaging = new GdPictureImaging();
using GdPictureOCR ocr = new GdPictureOCR();
// Load the image containing text to be extracted
int imageId = imaging.CreateGdPictureImageFromFile(@"input.png");
// Apply the image to the OCR engine for processing
ocr.SetImage(imageId);

Run text recognition

Execute OCR and read the recognized text result:

// Run OCR analysis to identify and extract text
string ocrResultId = ocr.RunOCR(OCRSpecialContext.None);
// Retrieve the recognized text content
string result = ocr.GetOCRResultText(ocrResultId);

Save extracted text

Write OCR output to a text file:

// Save the extracted text to a file
File.WriteAllText(@"output.txt", result);

Restrict the recognized characters

GdPictureOCR has three properties that control what the engine recognizes. Set them before calling RunOCR:

  • CharacterSet — The allowlist. The engine returns only the listed characters — for example, "0123456789" for digits only. The default, an empty string, recognizes all characters.
  • CharacterBlackList — The denylist. The engine ignores the listed characters. The default is an empty string.
  • OCRMode — OCRMode.FavorAccuracy (default) or OCRMode.FavorSpeed.

The example below recognizes English text, ignores digits, and checks the status after each step:

using GdPictureImaging filterImaging = new GdPictureImaging();
using GdPictureOCR filterOcr = new GdPictureOCR();
int filterImageId = filterImaging.CreateGdPictureImageFromFile(@"input.png");
if (filterImaging.GetStat() != GdPictureStatus.OK)
{
throw new Exception($"Loading the image failed: {filterImaging.GetStat()}");
}
try
{
filterOcr.SetImage(filterImageId);
filterOcr.AddLanguage(OCRLanguage.English);
// Ignore digits during recognition.
filterOcr.CharacterBlackList = "0123456789";
string filteredResultId = filterOcr.RunOCR();
if (filterOcr.GetStat() != GdPictureStatus.OK)
{
throw new Exception($"OCR failed: {filterOcr.GetStat()}");
}
File.WriteAllText(@"output_filtered.txt", filterOcr.GetOCRResultText(filteredResultId));
}
finally
{
// Release the OCR results and the image, even if a step fails.
filterOcr.ReleaseOCRResults();
filterImaging.ReleaseGdPictureImage(filterImageId);
}

To make the output searchable inside a PDF instead of saving plain text, refer to the image to searchable PDF guide.

Additional OCR options

Extend this workflow with:

  • Language-specific OCR configuration for targeted recognition
  • Confidence-based review logic
  • Region-based OCR for specific image areas
  • Layout-aware post-processing for structured documents

Conclusion

This workflow extracts text from an image and saves it as plain text for downstream processing.