Aspose.OCR Scanned PDF to Text for .NET
Aspose.OCR Scanned PDF to Text for .NET extracts text from individual scanned PDFs or batches of PDF files and page ranges. The licensed plugin scope includes PDF input, regular OCR, and table-related OCR methods with the area detection modes and settings listed below.
Installation and Setup
To get started, install the Aspose.OCR package into your .NET project via NuGet or from a locally downloaded file. For detailed steps, see the Installation guide. Before calling any OCR methods, configure metered licensing as described in the Metered Licensing documentation.
Supported Plugin Options
The plugin license enables these API capabilities:
| API area | Supported options |
|---|---|
| Licensed methods | Recognize, DetectTables, RecognizeTables |
| Input type | InputType.PDF |
| Area detection modes | DetectAreasMode.TABLE, DetectAreasMode.CURVED_TEXT, DetectAreasMode.LEAN, DetectAreasMode.MULTICOLUMN, DetectAreasMode.UNIVERSAL |
| 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 |
Features and Functionalities
Text Extraction from Scanned PDFs
- Supports both single-page and multi-page PDF input.
- Exposes text fragments along with their position, font attributes, and confidence scores.
- Provides layout metadata so developers can reconstruct or reflow content.
Table Recognition and Extraction
- Automatically detects table structures within scanned pages.
- Outputs table content as structured rows and cells with bounding box coordinates.
Searchable Document Conversion
- Embeds recognized text back into PDFs as an invisible layer, making them searchable without changing appearance.
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.PDF, add scanned PDF files or selected page ranges, configure RecognitionSettings, and call Recognize. Add multiple PDF files or page ranges with repeated input.Add(...) calls to recognize a batch in one request. Use DetectTables or RecognizeTables when the PDF pages contain tables.
Example: Extracting Text from Scanned PDFs
Aspose.OCR.Metered metered = new Aspose.OCR.Metered();
metered.SetMeteredKey("PublicKey", "PrivateKey");
Aspose.OCR.AsposeOcr recognitionEngine = new Aspose.OCR.AsposeOcr();
Aspose.OCR.OcrInput input = new Aspose.OCR.OcrInput(Aspose.OCR.InputType.PDF);
// Process selected pages from a PDF
input.Add("source1.pdf", 0, 3); // first 3 pages
// Process all pages from another PDF
input.Add("source2.pdf");
Aspose.OCR.RecognitionSettings recognitionSettings = new Aspose.OCR.RecognitionSettings();
recognitionSettings.Language = Aspose.OCR.Language.Latin;
Aspose.OCR.OcrOutput results = recognitionEngine.Recognize(input, recognitionSettings);
foreach (Aspose.OCR.RecognitionResult result in results)
{
Console.WriteLine(result.RecognitionText);
}
// Save results to file
results[0].Save("result.txt", Aspose.OCR.SaveFormat.Text);
results.Save("result.pdf", Aspose.OCR.SaveFormat.Pdf);
results.Save("result.docx", Aspose.OCR.SaveFormat.Docx);Output Formats and Saving Results
Use RecognitionResult.Save(...) to save a single recognized PDF page result, OcrOutput.Save(...) to save the whole PDF 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. Use Pdf to create a searchable PDF with the recognized text layer, or PdfNoImg when you need a PDF output without the original image background.
Tips and Best Practices
- Preprocess PDFs with supported filters such as deskew and threshold for improved accuracy.
- For low-quality scanned PDFs, apply supported preprocessing filters such as
PreprocessingFilter.AutoSkew(),Rotate(),Binarize(),Threshold(),ToGrayscale(), orMedian()before recognition. - Use the supported
DetectAreasModevalue that matches the PDF layout. - Set
ThreadsCountto1on low-powered machines to reduce CPU pressure; increaseThreadsCounton multi-core systems to speed up batch processing.
By combining OCR recognition with PDF input and table-related APIs, Aspose.OCR Scanned PDF to Text for .NET provides a focused solution for extracting text from scanned PDFs.