Aspose.OCR Scanned Image to Text for .NET
Aspose.OCR Scanned Image to Text for .NET extracts text from individual raster images or batches of images that contain structured document content, such as scanned contracts, agreements, book pages, articles, and newspapers. The licensed plugin scope is defined by the OCR plugin service and is limited to the API methods, input type, area detection modes, preprocessing filters, and recognition settings listed below.
Installation and Setup
To add Aspose.OCR Scanned Image to Text for .NET to your project, install the NuGet package and configure metered licensing:
- Install via NuGet (see detailed steps): Installation
- Enable metered licensing before first use: Metered Licensing
No other dependencies are required. After installation, simply reference the Aspose.OCR namespace in your code files.
Supported Plugin Options
The plugin license enables these API capabilities:
| API area | Supported options |
|---|---|
| Licensed methods | Recognize, DetectTables, RecognizeTables |
| Input type | InputType.SingleImage |
| Area detection modes | DetectAreasMode.UNIVERSAL, DetectAreasMode.LEAN, DetectAreasMode.MULTICOLUMN |
| Preprocessing filters | PreprocessingFilter.AutoSkew(), Binarize(), Resize(), Dilate(), Invert(), Rotate(), Scale(), ToGrayscale(), Threshold(), Median() |
| Language selection | RecognitionSettings.Language supports 154 Language enum values, including Auto, Multilanguage, and Universal |
| Common public recognition settings | RecognizeSingleLine, UpscaleSmallFont, LinesFiltration, ThreadsCount, AutomaticColorInversion |
| Plugin license restriction | Custom RecognitionAreas are not included; keep RecognitionAreas empty |
Skew correction is configured through PreprocessingFilter.AutoSkew(), not through RecognitionSettings. Manual rotation and other image cleanup steps can be configured with preprocessing filters such as Rotate(), Binarize(), ToGrayscale(), Threshold(), and Median(). Auto denoising, auto dewarping, contrast correction, and auto contrast are not listed for this plugin in the license service.
Supported Workflow
Use OcrInput with InputType.SingleImage, add one or more supported raster image files, and call Recognize with RecognitionSettings. Add multiple files with repeated input.Add(...) calls to recognize a batch in one request. For table-aware processing, use the licensed table APIs or one of the supported area detection modes listed above.
Example: Extract Text from Scanned Images
Aspose.OCR.Metered metered = new Aspose.OCR.Metered();
metered.SetMeteredKey("PublicKey", "PrivateKey");
// Initialize OCR engine
Aspose.OCR.AsposeOcr recognitionEngine = new Aspose.OCR.AsposeOcr();
// Add images to the recognition batch
Aspose.OCR.OcrInput input = new Aspose.OCR.OcrInput(Aspose.OCR.InputType.SingleImage);
input.Add("page1.png");
input.Add("page2.jpg");
// Configure recognition settings
Aspose.OCR.RecognitionSettings recognitionSettings = new Aspose.OCR.RecognitionSettings();
recognitionSettings.DetectAreasMode = Aspose.OCR.DetectAreasMode.MULTICOLUMN;
// Perform OCR for all images in the batch
Aspose.OCR.OcrOutput results = recognitionEngine.Recognize(input, recognitionSettings);
foreach (Aspose.OCR.RecognitionResult result in results)
{
Console.WriteLine(result.RecognitionText);
}
// Save results
results[0].Save("page1.txt", Aspose.OCR.SaveFormat.Text);
results.Save("result.pdf", Aspose.OCR.SaveFormat.Pdf);
results.Save("result.json", Aspose.OCR.SaveFormat.Json);Output Formats and Saving Results
Use RecognitionResult.Save(...) to save a single recognized image or page, OcrOutput.Save(...) to save the whole recognition batch, or AsposeOcr.SaveMultipageDocument(...) to combine several results into one output document.
Supported SaveFormat values are Text, Docx, Pdf, PdfNoImg, Xlsx, Xml, Json, HTML, EPUB, RTF, HOCR, Md, and Csv. You can also read recognized text, lines, confidence values, and layout data directly from the recognition result objects without saving to a file.
Tips and Best Practices
- Start with high-quality scans (300 DPI or above) to maximize accuracy.
- Use one of the supported
DetectAreasModevalues for the document layout you process. - For low-quality scans, apply supported preprocessing filters such as
PreprocessingFilter.AutoSkew(),Rotate(),Binarize(),Threshold(),ToGrayscale(), orMedian()before recognition. - Set
ThreadsCountto1on low-powered machines to reduce CPU pressure; increaseThreadsCounton multi-core systems to speed up batch processing.