Easiest Way to OCR Process PDF Documents in ASP.NET Core | Syncfusion Blogs
Live Chat Icon For mobile
Live Chat Icon
Popular Categories.NET  (182).NET Core  (26).NET MAUI  (233)Angular  (115)ASP.NET  (49)ASP.NET Core  (80)ASP.NET MVC  (85)Azure  (42)Black Friday Deal  (1)Blazor  (243)BoldSign  (15)DocIO  (24)Essential JS 2  (108)Essential Studio  (198)File Formats  (73)Flutter  (140)JavaScript  (227)Microsoft  (121)PDF  (86)Python  (1)React  (107)Streamlit  (1)Succinctly series  (131)Syncfusion  (988)TypeScript  (32)Uno Platform  (3)UWP  (3)Vue  (45)Webinar  (54)Windows Forms  (59)WinUI  (72)Word  (18)WPF  (165)Xamarin  (159)XlsIO  (38)Other CategoriesBarcode  (5)BI  (29)Bold BI  (8)Bold Reports  (2)Build conference  (11)Business intelligence  (55)Button  (4)C#  (164)Chart  (154)Chart of the week  (62)Cloud  (16)Company  (440)Dashboard  (8)Data Science  (3)Data Validation  (8)DataGrid  (74)Development  (696)Doc  (7)DockingManager  (1)eBook  (99)Enterprise  (22)Entity Framework  (7)Essential Tools  (13)Excel  (47)Extensions  (31)File Manager  (8)Gantt  (23)Gauge  (12)Git  (5)Grid  (31)HTML  (13)Installer  (2)Knockout  (2)Language  (1)LINQPad  (1)Linux  (2)M-Commerce  (1)Metro Studio  (11)Mobile  (530)Mobile MVC  (9)OLAP server  (2)Open source  (1)Orubase  (12)Partners  (21)PDF viewer  (48)Performance  (13)PHP  (2)PivotGrid  (5)Predictive Analytics  (6)Report Server  (3)Reporting  (8)Reporting / Back Office  (9)Rich Text Editor  (12)Road Map  (12)Scheduler  (54)Security  (5)SfDataGrid  (9)Silverlight  (21)Sneak Peek  (32)Solution Services  (4)Spreadsheet  (11)SQL  (15)Stock Chart  (1)Surface  (4)Tablets  (5)Theme  (12)Tips and Tricks  (112)UI  (426)Uncategorized  (68)Unix  (2)User interface  (67)Visual State Manager  (2)Visual Studio  (31)Visual Studio Code  (19)Web  (650)What's new  (355)Windows 8  (19)Windows App  (2)Windows Phone  (15)Windows Phone 7  (9)WinRT  (26)
Easiest Way to OCR Process PDF documents in ASP.NET core_edited

Easiest Way to OCR Process PDF Documents in ASP.NET Core

Optical character recognition (OCR) is a technology used to convert scanned paper documents, in the form of PDF files or images, into searchable, editable data.

The Syncfusion OCR processor library has extended support to OCR process PDF documents and other scanned images in the .NET Core platform from version In this blog, I am going to create an ASP.NET Core web application to OCR process a PDF document. The steps are:

Experience a leap in PDF technology with Syncfusion's PDF Library, shaping the future of digital document processing.

Create an ASP.NET Core web application

Follow these steps to create an ASP.NET Core web application in Visual Studio 2019:

  1. In Visual Studio 2019, go to File > New and then select Project.
  2. Select Create a new project.
  3. Select the ASP.NET Core Web Application template.
  4. Enter the Project name and then click Create. The Project template dialog will be displayed.

Create a new ASP.NET Core Web application dialog box

Install necessary NuGet packages to OCR process PDF documents

Follow these steps to install the Syncfusion.PDF.OCR.Net.Core NuGet package in the project:

  1. Right-click on the project and select Manage NuGet Packages.
    Select Mange NuGet Packages
  2. Search for the Syncfusion.PDF.OCR.Net.Core package and install it.Select Syncfusion.PDF.OCR.NET.Core and install

Unleash the full potential of Syncfusion's PDF Library! Explore our advanced resources and empower your apps with cutting-edge functionalities.

Perform OCR processing on PDF document

Follow these steps to perform OCR processing on a PDF document in ASP.NET Core:

  1. Syncfusion’s OCR processor internally uses Tesseract libraries to perform OCR, so please copy the necessary tessdata and TesseractBinaries folders from the NuGet package folder to the project folder to use the OCR feature. The tessdata folder contains OCR language data and Tesseractbinaries contains the wrapper assemblies for Tesseract OCR. Please use the following link to download OCR language data for other languages.
    https://github.com/tesseract-ocr/tessdataCopy tessdata and tesseractbinaries folder from NuGet folder
    Paste tessdata and TesseractBinaries to the project folder
  2. Set Copy to Output Directory to Copy if newer for Data, tessdata, and TesseractBinaries folders.Set Copy to Output Directory to Copy if newer
  3. Add a new button in index.cshtml.
    @{ Html.BeginForm("PerformOCR", "Home", FormMethod.Post);
            <input type="submit" value="Perform OCR" class=" btn" />
  4. Include the following namespaces in HomeController.cs.
    using Microsoft.AspNetCore.Hosting;
    using Microsoft.AspNetCore.Mvc;
    using Syncfusion.OCRProcessor;
    using Syncfusion.Pdf.Graphics;
    using Syncfusion.Pdf.Parsing;
    using System.IO;
  5. Include the following code example in HomeController.cs to perform the OCR processing.
    public IActionResult PerformOCR()
    string binaries = Path.Combine(_hostingEnvironment.ContentRootPath, "TesseractBinaries", "Windows");
    //Initialize OCR processor with tesseract binaries.
    OCRProcessor processor = new OCRProcessor(binaries);
    //Set language to the OCR processor.
    processor.Settings.Language = Languages.English;
    string path = Path.Combine(_hostingEnvironment.ContentRootPath, "Data", "times.ttf");
    FileStream fontStream = new FileStream(path, FileMode.Open);
    //Create a true type font to support unicode characters in PDF.
    processor.UnicodeFont = new PdfTrueTypeFont(fontStream, 8);
    //Set temporary folder to save intermediate files.
    processor.Settings.TempFolder = Path.Combine(_hostingEnvironment.ContentRootPath, "Data");
    //Load a PDF document.
    FileStream inputDocument = new FileStream(Path.Combine(_hostingEnvironment.ContentRootPath, "Data", "PDF_succinctly.pdf"), FileMode.Open);
    PdfLoadedDocument loadedDocument = new PdfLoadedDocument(inputDocument);
    //Perform OCR with language data.
    string tessdataPath = Path.Combine(_hostingEnvironment.ContentRootPath, "Tessdata");
    processor.PerformOCR(loadedDocument, tessdataPath);
    //Save the PDF document.
    MemoryStream outputDocument = new MemoryStream();
    outputDocument.Position = 0;
    //Dispose OCR processor and PDF document.
    //Download the PDF document in the browser.
    FileStreamResult fileStreamResult = new FileStreamResult(outputDocument, "application/pdf");
    fileStreamResult.FileDownloadName = "OCRed_PDF_document.pdf";
    return fileStreamResult;

By executing this example, you will get the PDF document shown in the following image.

OCRed PDF document

Witness the advanced capabilities of Syncfusion's PDF Library with feature showcases.

Publish OCR application in Azure App Service

Follow these steps to publish the OCR application in Azure App Service:

  1. In Solution Explorer, right-click the project and choose Publish (or use the Build > Publish menu item).Choose Publish from the given option
  2. In the Pick a publish target dialog box, choose App Service, select Create New and click Create Profile.Pick a publish target dialog
  3. In the Create App Service dialog box that appears, sign in with your Azure account (if necessary). Then, the default app service settings populate the fields. Click Create.
    Create App Service Dialog
  4. Visual Studio now deploys the app to your Azure App Service, and the web app loads in your browser. The project properties Publish pane shows the site URL and other details. Click Publish to publish the application in Azure App Service.
    Publish Window

After publishing the application, you can perform OCR processing by navigating to the site URL.

Perform OCR PDF Document

Note: Adobe provides an easy-to-use method for turning scanned files into editable PDF documents instantly, with editable text and custom fonts that look just like the original file. For more details, refer to the article How to edit scanned documents.

GitHub reference

You can find examples of performing OCR on ASP.NET Core applications and Azure App Service in the GitHub repository.

Syncfusion’s high-performance PDF Library allows you to create PDF documents from scratch without Adobe dependencies.


In this blog post, we have learned to perform OCR processing on PDF documents in ASP.NET Core web applications and publish the applications in Azure App Service.

Take a moment to peruse our documentation, where you’ll find other options and features, all with accompanying code examples.

If you have any questions about these features, please let us know in the comments below. You can also contact us through our support forum, Direct-Trac, or feedback portal. We are happy to assist you!

If you liked this article, we think you would also like the following articles about our PDF Library:


Share this post:

Comments (4)

Object reference not set to an instance of an object on tessdataPath.


Thank you for using Syncfusion products.

On our further analysis, the reported issue occurs due to the provided TTF font file is not valid. We are trying to install this font on our end, but we could not able to install the font.

However, we can resolve this issue by providing a valid TTF font. We have replaced the proper TTF font in the sample and it’s working fine.

Please find the download link below,

Please let us know if you need any further assistance with this.

Gowthamraj K

On IIS – Could not find a part of the path ‘C:\inetpub\wwwroot\mysite\x64’ – despite it is working locally without any issue..

When debugging tesseractbinaries path on IIS – the path it is valid, so statments:

var tesseractBinariesPath = ConfigurationHelper.MapPath(“Tesseractbinaries\\Windows\\”);
var tesseractDataPath = ConfigurationHelper.MapPath(“tessdata\\”);

which gives on IIS gives following results:

and tesseract files are in that location (C:\inetpub\wwwroot\mysite\Tesseractbinaries\Windows\x64)

Custom MapPath function is looking like this:

public static string MapPath(string path) {
path = path.Replace(“~\\”, “”);
return Path.Combine(env.ContentRootPath, path);

BUT when instancing OCR processor, I’m getting error:
Could not find a part of the path ‘C:\inetpub\wwwroot\mysite\x64’

I don’t understand from where OCRProcessor searches for and gets ‘C:\inetpub\wwwroot\mysite\x64’ and why it is so confused on IIS when in local development is working normally..


The reported exception may occur due to missing or mismatched assemblies of the Tesseract binaries and Tesseract data from the OCR processor. We have created a sample to perform the OCR operation with the test document, it is working properly. We are unable to reproduce the reported exception on our end. Please make sure the path of the Tesseract binaries and Tesseract data are provided properly. Kindly please try the below sample on your end and let us know the result.

Sample: https://www.syncfusion.com/downloads/support/directtrac/general/ze/OCRCoreSample782347509

Note: The above sample contains the Tesseract binaries and Tess data folder in a project location.

Please refer to the below link for more information,
UG: https://help.syncfusion.com/file-formats/pdf/working-with-ocr/dot-net-core
Troubleshooting: https://help.syncfusion.com/file-formats/pdf/working-with-ocr/dot-net-core#troubleshooting

OCR processor required read/write and execute permission of the temporary and Tesseract binaries folder. If the temporary folder does not have elevated permission, the reported exception may occur. So, kindly ensure the respective user group has permission for the temp and Tesseract folder. When hosting the application to IIS, our processor makes use of the system temporary folder (By default, C://Windows//Temp). So, please make sure this temp path, the binaries path has required permission for the respective user group (IIS_IUSRS). If you are hosting the application in IIS, please try to add the IIS_IUSRS user group and provide full access permission to the temp folder.

If you still face the same exception, we request you to share the modified sample or complete code snippet, input document, environment details (such as OS, bit version, culture settings, etc) Syncfusion product version, Tesseract version, output document, product version to check the issue in our end. So, it will be helpful for us to analyze and assist you further on this.

Gowthamraj K

Comments are closed.

Popular Now

Be the first to get updates

Subscribe RSS feed

Be the first to get updates

Subscribe RSS feed