OCR in PDF Using Tesseract Open-Source Engine | Syncfusion Blogs
Live Chat Icon For mobile
Live Chat Icon
Popular Categories.NET  (172).NET Core  (29).NET MAUI  (192)Angular  (107)ASP.NET  (51)ASP.NET Core  (82)ASP.NET MVC  (89)Azure  (40)Black Friday Deal  (1)Blazor  (209)BoldSign  (12)DocIO  (24)Essential JS 2  (106)Essential Studio  (200)File Formats  (63)Flutter  (131)JavaScript  (219)Microsoft  (118)PDF  (80)Python  (1)React  (98)Streamlit  (1)Succinctly series  (131)Syncfusion  (882)TypeScript  (33)Uno Platform  (3)UWP  (4)Vue  (45)Webinar  (49)Windows Forms  (61)WinUI  (68)WPF  (157)Xamarin  (161)XlsIO  (35)Other CategoriesBarcode  (5)BI  (29)Bold BI  (8)Bold Reports  (2)Build conference  (8)Business intelligence  (55)Button  (4)C#  (146)Chart  (125)Cloud  (15)Company  (443)Dashboard  (8)Data Science  (3)Data Validation  (8)DataGrid  (62)Development  (613)Doc  (7)DockingManager  (1)eBook  (99)Enterprise  (22)Entity Framework  (5)Essential Tools  (14)Excel  (37)Extensions  (22)File Manager  (6)Gantt  (18)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  (488)Mobile MVC  (9)OLAP server  (1)Open source  (1)Orubase  (12)Partners  (21)PDF viewer  (41)Performance  (12)PHP  (2)PivotGrid  (4)Predictive Analytics  (6)Report Server  (3)Reporting  (10)Reporting / Back Office  (11)Rich Text Editor  (12)Road Map  (12)Scheduler  (52)Security  (3)SfDataGrid  (9)Silverlight  (21)Sneak Peek  (31)Solution Services  (4)Spreadsheet  (11)SQL  (10)Stock Chart  (1)Surface  (4)Tablets  (5)Theme  (12)Tips and Tricks  (112)UI  (368)Uncategorized  (68)Unix  (2)User interface  (68)Visual State Manager  (2)Visual Studio  (30)Visual Studio Code  (17)Web  (577)What's new  (313)Windows 8  (19)Windows App  (2)Windows Phone  (15)Windows Phone 7  (9)WinRT  (26)
Optical Character Recognition

Optical Character Recognition in PDF Using Tesseract Open-Source Engine

Optical character recognition (OCR) is a technology used to convert scanned paper documents, in the form of PDF files or images, to searchable, editable data. Paper documents—such as brochures, invoices, contracts, etc.—are sent via email. This process usually involves a scanner that converts the document to lots of different colors, known as a raster image. In order to extract the data and repurpose the content of the document, an OCR engine is necessary. The OCR engine detects the characters present in the image, puts those characters into words, and then into sentences, enabling you to search and edit the content of the document.

Tesseract engine

Tesseract is an optical character recognition engine, one of the most accurate OCR engines currently available. It is licensed under Apache 2.0 and has been developed by Google since 2006.

Transform your PDF files effortlessly in C# with just five lines of code using Syncfusion's comprehensive PDF Library!

Getting Started with Essential PDF and Tesseract Engine

Syncfusion Essential PDF supports OCR by using the Tesseract open-source engine. With a few lines of code, a scanned paper document containing raster images is converted to a searchable and selectable document.

You can download the OCR processor product setup here.

Deployment Requirements

The following assemblies are required to deploy Essential PDF and the OCR process.

Syncfusion assemblies

  • Syncfusion.Compression.Base.dll
  • Syncfusion.Pdf.Base.dll
  • Syncfusion.OcrProcessor.Base.dll

Tesseract assemblies

  • SyncfusionTessaract.dll (Tesseract Engine Version 3.02)
  • liblept168.dll (Leptonica image processing library used by Tesseract engine)

Referencing OCR assemblies in a .NET project

To reference the OCR assemblies in a .NET project:

  1. Open the Solution Explorer of the application you have created. Right-click the Reference folder and then click Add References.
  2. Add the following assemblies as references in the application:
    • Syncfusion.Compression.Base.dll
    • Syncfusion.Pdf.Base.dll
    • Syncfusion.OcrProcessor.Base.dll
  3. SyncfusionTessaract.dll and liblept168.dll should not be added as a reference. They should be kept in the local machine, and the location of the assemblies should be passed as a parameter to the OCR processor.

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

Performing OCR for a scanned paper document

1. To perform optical character recognition, as a first step, create the OCR processor by generating an object of the OCRProcessor class. It is mandatory for the constructor of the OCRProcessor class to accept the path of the Tesseract binaries, SyncfusionTessaract.dll, and liblept168.dll.

//Initializes the OCR processor by providing Tesseract binaries(SyncfusionTesseract.dll and liblept168.dll)
//to the OCR processor overload.
OCRProcessor processor = new OCRProcessor(@"TesseractBinaries");

2. The PDF document that has to undergo the optical character recognition is loaded by using the PdfLoadedDocument class.

//Loads a PDF document.
PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf");

3. The next step is to set the language for the OCR process and start the OCR process with the input of the language dictionary. Tesseract supports a variety of languages. The following code explains the OCR process for English and how to provide the English dictionary input.

//Sets OCR language to process.
processor.Settings.Language = "eng";
//Processes OCR by providing PDF document, data dictionary, and language.
processor.PerformOCR(loadedDocument, @"Tessdata");

Note: You can get the Tesseract binaries SyncfusionTessaract.dll, liblept168.dll, and the language pack (tessdata)— by downloading the OCR processor zip file from the following location: https://www.syncfusion.com/downloads/latest-version

4. The final step is to save the PDF document and dispose of the PdfLoadedDocument object. The saved PDF document now contains the contents in a searchable form.

//Saves the OCR-processed PDF document to a disk.
loadedDocument.Save("Sample.pdf");
loadedDocument.Close(true);

Performing OCR on a section of the document

Optical character recognition can also be performed on a section of a document rather than the complete document. The following documentation link provides a code sample and explanation.

Embark on a virtual tour of Syncfusion's PDF Library through interactive demos.

Multiple language support for OCR

The Tesseract engine, starting from version 3, supports a variety of languages such as Arabic, English, Bulgarian, Catalan, Czech, Chinese and German as given in the following table.

Essential PDF also supports all these languages in the OCR processor. By default, Syncfusion ships only the English dictionary in the package. The dictionary packs for the other languages can be downloaded from the following online location:

https://github.com/tesseract-ocr/tessdata

  1. The dictionary packs from the above link can be downloaded, extracted to a folder, and the location of the folder can be passed to the PerformOCR() method of the OCRProcessor class.
  2. It is also mandatory to change the corresponding language code in the OCRProcessor.Settings.Language property. For example, to perform optical character recognition in German, the property should be set as processor.Settings.Language = “deu”;

The following table shows the complete set of supported languages and their language codes.

Language

Language code

Arabicara
Azerbaijaniaze
Bulgarianbul
Catalancat
Czechces
Simplified Chinesechi_sim
Traditional Chinesechi_tra
Cherokeechr
Danishdan
Danish (Fraktur)dan-frak
German, standard and Fraktur scriptdeu
Greekell
Englisheng
Old Englishenm
Esperantoepo
Estonianest
Finnishfin
Frenchfra
Old Frenchfrm
Galicianglg
Hebrewheb
Hindihin
Croatianhrv
Hungarianhun
Indonesianind
Italianita
Japanesejpn
Koreankor
Latvianlav
Lithuanianlit
Dutchnld
Norwegiannor
Polishpol
Portuguesepor
Romanianron
Russianrus
Slovakianslk
Slovenianslv
Albaniansqi
Spanishspa
Serbiansrp
Swedishswe
Tamiltam
Telugutel
Tagalogtgl
Thaitha
Turkishtur
Ukrainianukr
Vietnamesevie

Tips for improving OCR accuracy

You can improve the accuracy of the OCR process by choosing the correct compression method when converting the scanned paper to a TIFF image and then to a PDF document:

  • Tesseract works best with text when at least 300 dots per inch (DPI) are used, so it is beneficial to resize images.
  • Compression:
    • Use (zip) lossless compression for color or gray-scale images.
    • Use CCITT Group 4 or JBIG2 (lossless) compression for monochrome images. This ensures that optical character recognition works on the highest-quality image, thereby improving the OCR accuracy. This is especially useful in low-resolution scans.
  • In addition, rotated images and skewed images can also affect the accuracy and readability of the OCR process.

For more details regarding quality improvement, refer to the following link:

https://github.com/tesseract-ocr/tesseract/wiki/ImproveQuality.

Join thousands of developers who rely on Syncfusion for their PDF needs. Experience the difference today!

The sample can be checked-out from this GitHub repository. Give it a star, if it is being useful to you.

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

If you are new to our PDF library, it is highly recommended that you follow our Getting Started guide.

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

If you like this blog post, we think you’ll also like the following resources:

This post was originally published on February 20, 2015.

Tags:

Share this post:

Comments (11)

doest it support .net core project

Hi Nick,

At present we do not support OCR processor in .NET Core project. We will consider your request and will update you once the feature is implemented in any of our upcoming release.

Regards,
George

OCR will support for telugu language ?

processor.Settings.Language = “tel”;

//Set tesseract OCR engine

processor.Settings.TesseractVersion = TesseractVersion.Version3_02;

//Process OCR by providing the bitmap image, data dictionary and language

string ocrText = processor.PerformOCR(image, @”../../OCR/Tessdata/”);

Using this code throw an error.

Can you please resolve this ?

For additional info.

I have placed all the trained data in the respective path.

Sowmiya Loganathan
Sowmiya Loganathan

Hi Chandran,

Could you please download the Telegu tessdata (tel.traineddata) from the below link to work with Telugu characters while performing OCR,
https://github.com/tesseract-ocr/tesseract/wiki/Data-Files#data-files-for-version-302

Please try with the above tessdata and let us know the result. If you still facing any issue, kindly share the error details and input file. It will helpful for us to provide the precise solution on this.

Regards,
Sowmiya Loganathan

doest it support .net core project now?

Sowmiya Loganathan
Sowmiya Loganathan

Hi Dayakar,

At present we do not support performing OCR in the ASP.NET Core platform. We have already logged a feature request for this and we have planned to implement this feature in our upcoming Volume 1 release 2020 which is expected to available by March 2020 tentatively. We will let you know once the feature is implemented. The status of implementation can be tracked through our Feature Management System:
https://www.syncfusion.com/feedback/4467/support-for-performing-ocr-in-a-pdf-document

Please let us know if you have any concerns about this.

Regards,
Sowmiya Loganathan

Sivakumar Balakrishnan
Sivakumar Balakrishnan

Using Tesseract How I can read the text from pdf file

Sowmiya Loganathan
Sowmiya Loganathan

Hi Sivakumar,

The text from OCRed document can be read in below two ways,

• Code snippet
//Process OCR by providing the PDF document and Tesseract data
string str = processor.PerformOCR(lDoc, @”../../Tessdata/”, true);

• Select text (Ctrl+A) from resultant OCR’ed PDF document and paste it to text file.

Regards,
Sowmiya Loganathan

Sowmiya Loganathan
Sowmiya Loganathan

Hi Sivakumar,

We can also extract the text from PDF document using ExtractText method. Please refer the below documentation for more details,
https://help.syncfusion.com/file-formats/pdf/working-with-text-extraction

Note: The PerformOCR method returns only the text OCRed by OCRProcessor. Other existing text can be extracted by using this feature.

Regards,
Sowmiya Loganathan

Sowmiya Loganathan
Sowmiya Loganathan

Hi Everyone,

We have provided support for the feature “Support for performing OCR in a PDF document in ASP.NET Core platform” from the version 18.1.0.42. Please refer the below link for more details,
https://www.syncfusion.com/blogs/post/easiest-way-to-ocr-process-pdf-documents-in-asp-net-core.aspx

Regards,
Sowmiya Loganathan

Comments are closed.

Popular Now

Be the first to get updates

Subscribe RSS feed

Be the first to get updates

Subscribe RSS feed

Table of Contents

Scroll To Top