As part of the LEAD Technologies 25th anniversary, we are creating 25 projects in 25 days to celebrate LEAD’s depth of features and ease of use. Today’s project comes from Faris.
What it Does
This C# console application will scan a page, extract text with OCR and save to PDF using LEADTOOLS Version 19.
Development Progress Journal
Hello, my name is Faris and I’m going to create a console application which will scan a page from a scanner using TWAIN, recognize the text in the scanned page, and finally, save the recognized page as searchable PDF.
In this project, I will use LEADTOOLS Recognition Imaging SDK and program using .NET C# programming language.
The LEADTOOLS Recognition Imaging SDK provides me with the ability to scan from a TWAIN scanner, recognize the text in images using Optical Character Recognition (OCR) and save recognized images to document formats (PDF, DOCX, TXT).
It should be noted this application will recognize printed text in English alphabets, but not hand-written text. This can be customized to suit the programmer’s needs as our LEADTOOLS OCR engines support multiple languages and the Professional engine supports Intelligent Character Recognition (ICR).
First, I will start with a new Console Application in Visual Studio 2010. I will also add the needed SDK references for TWAIN, OCR and document writing functionalities.
I have now added the necessary code for starting up the TWAIN session, enumerating the scanners connected to the device and acquiring the image from the scanner. This took about 30 minutes of work.
Next came recognizing the acquired image. The OCR engine must first be started, then the text in the image should be placed inside zones, and then the image will be ready for recognition. For zoning the image, I used the `AutoZone` method as I want to recognize the whole page, not a specific part of it. I found a really useful code example when searching LEADTOOLS online help documentation for the `AutoZone` method:
I have now finished adding the code for recognizing the scanned image. This took about an hour.
The next step is to save the recognized document as a searchable PDF. Luckily, the example I referenced earlier shows the code to achieve that. All I need to do is add the code for saving the recognized document in such a way to work with the previous step. The programmer can modify this part of the project to prompt the user to specify which file format the user wishes to save the output file as and also specify the output file’s name.
This part is now done and took about 30 minutes.
Finally, I’ll work on error handling and testing the code. I will test the application when 2 scanners are connected and when one scanner is connected. Because this is a console application, I will add multiple lines of code to write on the console the current operation being done to make the application informative for the user.
The final part is now done with about 2 hours of work. The total work time on the project, including developing, debugging and testing the program, was about 4 hours. Without the help of LEADTOOLS SDK, I wouldn’t have been able to finish the core functionality code within 2 hours, thus finishing the whole application in less than a single day’s work.
Download the Project
The source code for this sample project can be downloaded from here. To run the project, extract it to the C:/LEADTOOLS 19/Examples/DotNet/CS directory.