A quick start .NET console project that shows how to extract text from scanned PDFs using the Syncfusion® OCR Library.
Framework and SDKs
- .NET SDK (version 5.0 or later)
IDEs
- Visual Studio 2019/ Visual Studio 2022
We will create a new .NET console application, add the Syncfusion® OCR library package, and write the code
//Initialize the OCR processor.
using (OCRProcessor processor = new OCRProcessor())
{
//Get stream from an existing PDF document.
FileStream stream = new FileStream("Input.pdf", FileMode.Open);
//Load the PDF document.
PdfLoadedDocument loadedDocument = new PdfLoadedDocument(stream);
//Set OCR language.
processor.Settings.Language = Languages.English;
//Perform OCR with input document.
processor.PerformOCR(loadedDocument);
//Create file stream.
using (FileStream outputFileStream = new FileStream("Output.pdf", FileMode.Create, FileAccess.ReadWrite)) {
//Save the PDF document to file stream.
loadedDocument.Save(outputFileStream);
}
//Close the document.
loadedDocument.Close(true);
}We will create a new .NET console application, add the Syncfusion® OCR library package, and write the code
//Initialize the OCR processor.
using (OCRProcessor processor = new OCRProcessor()) {
//Get stream from an existing PDF document.
FileStream stream = new FileStream("Input.pdf", FileMode.Open);
//Load the PDF document.
PdfLoadedDocument loadedDocument = new PdfLoadedDocument(stream);
//Set OCR language.
processor.Settings.Language = Languages.English;
//Assign rectangles to the page.
RectangleF rect = new RectangleF(0, 100, 950, 150);
List<PageRegion> pageRegions = new List<PageRegion>();
//Create page region.
PageRegion region = new PageRegion();
//Set page index.
region.PageIndex = 0;
//Set page regions.
region.PageRegions = new RectangleF[] { rect };
//Add region to page region.
pageRegions.Add(region);
//Set the regions.
processor.Settings.Regions = pageRegions;
//Perform OCR with input document.
processor.PerformOCR(loadedDocument);
//Create file stream.
using (FileStream outputFileStream = new FileStream("Output.pdf", FileMode.Create, FileAccess.ReadWrite)) {
//Save the PDF document to file stream.
loadedDocument.Save(outputFileStream);
}
//Close the document.
loadedDocument.Close(true);
}We will create a new .NET console application, add the Syncfusion® OCR library package, and write the code
//Initialize the OCR processor.
using (OCRProcessor processor = new OCRProcessor()) {
//Get stream from an existing PDF document.
FileStream stream = new FileStream("Input.jpg", FileMode.Open);
//Set OCR language.
processor.Settings.Language = Languages.English;
FileStream fontStream = new FileStream("ARIALUNI.ttf", FileMode.Open);
//Set the unicode font.
processor.UnicodeFont = new PdfTrueTypeFont(fontStream, true, PdfFontStyle.Regular, 10);
//Set the PDF conformance level.
processor.Settings.Conformance = PdfConformanceLevel.Pdf_A1B;
//Process OCR by providing the image.
PdfDocument document = processor.PerformOCR(stream);
//Create file stream.
using (FileStream outputFileStream = new FileStream("Output.pdf", FileMode.Create, FileAccess.ReadWrite)) {
//Save the PDF document to file stream.
document.Save(outputFileStream);
}
//Close the document.
document.Close(true);
}We will create a new .NET console application, add the Syncfusion® OCR library package, and write the code
//Initialize the OCR processor.
using (OCRProcessor processor = new OCRProcessor()) {
//Get stream from an existing PDF document.
FileStream stream = new FileStream("Input.jpg", FileMode.Open);
//Set OCR language.
processor.Settings.Language = Languages.English;
//Perform the OCR process for an image steam.
string OCRText = processor.PerformOCR(stream, processor.TessDataPath);
//Write the OCR'ed text in text file.
using (StreamWriter writer = new StreamWriter("OCRText.txt", true)) {
writer.WriteLine(OCRText);
}
}- Download this project to a location in your disk.
- Open the solution file using Visual Studio.
- Rebuild the solution to install the required NuGet package.
- Run the application.
- Product page: Syncfusion® PDF Framework
- Documentation page: Syncfusion® .NET PDF library
- Online demo: Syncfusion® .NET PDF library - Online demos
- Blog: Syncfusion® .NET PDF library - Blog
- Knowledge Base: Syncfusion® .NET PDF library - Knowledge Base
- EBooks: Syncfusion® .NET PDF library - EBooks
- FAQ: Syncfusion® .NET PDF library - FAQ
- For any other queries, reach our Syncfusion® support team or post the queries through the community forums.
- Request new feature through Syncfusion® feedback portal.
This is a commercial product and requires a paid license for possession or use. Syncfusion’s licensed software, including this component, is subject to the terms and conditions of Syncfusion's EULA. You can purchase a licnense here or start a free 30-day trial here.
Founded in 2001 and headquartered in Research Triangle Park, N.C., Syncfusion® has more than 26,000+ customers and more than 1 million users, including large financial institutions, Fortune 500 companies, and global IT consultancies.
Today, we provide 1600+ components and frameworks for web (Blazor, ASP.NET Core, ASP.NET MVC, ASP.NET WebForms, JavaScript, Angular, React, Vue, and Flutter), mobile (Xamarin, Flutter, UWP, and JavaScript), and desktop development (WinForms, WPF, WinUI(Preview), Flutter and UWP). We provide ready-to-deploy enterprise software for dashboards, reports, data integration, and big data processing. Many customers have saved millions in licensing fees by deploying our software.



