How to OCR Scanned Images to Text In ASP.NET


Read Text from Scanned PDF or Other Images in ASP.NET 

It’s a fast-paced world. Customers expect the work to be delivered in a short time. We often hear from anxious customers that it’s an urgent project that needs to be completed in a month.

This is what Dynamic Web TWAIN is designed for – to save your time and help you build a document management solution rapidly.

Dynamic Web TWAIN is a TWAIN SDK which enables you to interact with TWAIN scanners with just a couple of lines of code in JavaScript. Combined the OCR Professional Engine, you can easily create a document workflow of scanning documents and read text from images in your web application.

Try OCR Online Demos

Blow is an OCR online demo which you can try:

Server-Side OCR Online Demo
This demo uploads the images to the server and performs OCR on the server-side.

Want to try the samples yourself?
Get Sample Code NOW

Code Snippets

Below we will show some code snippets of doing TWAIN scanning and client-side OCR in JavaScript using Dynamic Web TWAIN.

Scan Images

Dynamic Web TWAIN provides easy APIs for you to customize scanning settings and acquire images from TWAIN scanners.

function acquireImage() {
    DWObject.SelectSourceByIndex(document.getElementById("source").selectedIndex); //select an available TWAIN scanners    
    //set scanning settings like pixel type, resolution, ADF ect.
    DWObject.IfShowUI = false; //don't show the user interface of the scanner
	DWObject.PixelType = 1; //scan in gray
    DWObject.Resolution = 300; 
    DWObject.IfFeederEnabled = true; //scan from auto feeder
    DWObject.IfDuplexEnabled = false;   
  	DWObject.IfDisableSourceAfterAcquire = true;
    //acquire images from scanners

Download OCR Professional Module

To use the OCR Professional module for client-side OCR, you will need to include ocrpro.js in the head and also download the OCR Pro DLL.

<script type="text/javascript" language="javascript" src="Resources/addon/dynamsoft.webtwain.addon.ocrpro.js">


var CurrentPathName = unescape(location.pathname);
CurrentPath = CurrentPathName.substring(0, CurrentPathName.lastIndexOf("/") + 1);
DWObject.Addon.OCRPro.Download(CurrentPath + "Resources/addon/", OnSuccess, OnFailure);

Perform OCR Recognition

It’s as easy as below to call the JS OCR recognition API to extract text from scanned images.

DWObject.Addon.OCRPro.Recognize(0, GetOCRProInfo, GetErrorInfo); // 0 is the index of the image

You can also use mouse to select an area of the image and do zonal OCR.

var zoneArray = [];
var zone = Dynamsoft.WebTwain.Addon.OCRPro.NewOCRZone(_iLeft, _iTop, _iRight, _iBottom);
DWObject.Addon.OCRPro.RecognizeRect(0, zoneArray, GetRectOCRProInfo, GetErrorInfo);

Return OCR Results

You can save the OCR results in txt, csv, rtf, xml or pdf.

 function DoOCR() {                
            if (DWObject) {

                var saveTye = "";
                var fileType = "";
                switch (OCROutputFormat[document.getElementById("ddlOCROutputFormat").selectedIndex].val) {
                    case EnumDWT_OCRProOutputFormat.OCRPFT_TXTS:
                        fileType = ".txt";
                        saveTye = "Plain Text(*.txt)";
                    case EnumDWT_OCRProOutputFormat.OCRPFT_TXTCSV:
                        fileType = ".csv";
                        saveTye = "CSV(*.csv)";
                    case EnumDWT_OCRProOutputFormat.OCRPFT_TXTF:
                        fileType = ".rtf";
                        saveTye = "Rich Text Format(*.rtf)";
                    case EnumDWT_OCRProOutputFormat.OCRPFT_XML:
                        fileType = ".xml";
                        saveTye = "XML Document(*.xml)";
                    case EnumDWT_OCRProOutputFormat.OCRPFT_IOTPDF:
                    case EnumDWT_OCRProOutputFormat.OCRPFT_IOTPDF_MRC:
                        fileType = ".pdf";
                        saveTye = "PDF(*.pdf)";
                var fileName = "result" + fileType;

                DWObject.ShowFileDialog(true, saveTye, 0, "", fileName, true, false, 0); 


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Subscribe Newsletter

Subscribe to our mailing list to get the monthly update.