OCR: How to C#
Using OCR SDK for C#.NET
Sample C#.NET Codes
Install, Deploy and Distribute
Home ›› XImage.OCR ›› C# OCR: Install, Deploy and Distribute

C#: Install, Deploy and Distribute .NET OCR SDK

C# Guide for How to Implement .NET OCR SDK Installation, Deployment and Distribution

If you have already downloaded production or free evaluation package of our XImage.OCR for .NET, you may find four DLL assemblies, namely RasterEdge.Imaging.Basic.Codec.dll, RasterEdge.Imaging.Basic.dll, RasterEdge.XImage.OCR.dll, and RasterEdge.XImage.OCR.Tesseract.dll. All these DLLs are indispensable for implementing high performance OCR technology in your Visual C# project. Now, let's see details for installing, deploying and distributing .NET OCR SDK.

Related .net document control helps:
asp.net mvc document viewer: ASP.NET MVC Document Viewer: view, annotate, redact files on ASP.NET MVC web projects
asp.net word document viewer: ASP.NET Office Word Document Viewer: view Word doc files online using C# in ASP.NET MVC web applications
asp.net document viewer control: EdgeDoc:ASP.NET Document Viewer C# Control: Open, view, annotate, redact, convert documents online in C#, VB.NET, AS...
asp.net pdf viewer control: ASP.NET PDF Viewer Control: view, navigate, zoom Adobe PDF document in C# ASP.NET
asp.net image viewer zoom: ASP.NET Image Viewer Control(MVC & WebForms): view, annotate, redact, convert image files in html, JQuery
asp.net mvc text file viewer: ASP.NET Text file viewer in MVC, WebForms: Open, view, annotate, convert txt files in C# ASP.NET
asp.net annotate pdf: ASP.NET Annotate PDF Control: annotate, comment, markup PDF document online using ASP.NET C#

System Requirements

To use our OCR product successfully, please firstly make sure your computer for application development is compatible with the following requirements.

Operation System: Windows XP, Windows 7 or greater

.NET Framework: .NET Framework 2.0 or greater

MemorySize: 1GB

Install OCR SDK into Visual Studio C# Project

This section describes how to install RasterEdge XImage.OCR for .NET into Visual Studio C# application. Please do as follows.

Add necessary references to your C#.NET project. Right-click the project, select "Add Reference..." to locate and add the following DLLs as project references;









Use corresponding namespaces;

  using RasterEdge.XImage.OCR;

  using RasterEdge.Imaging.Raster.Core;

Note: When you get the error "Could not load file or assembly 'RasterEdge.Imaging.Basic' or any other assembly or one of its dependencies. An attempt to load a program with an incorrect format", please check your configure as follows:


       If you are using x64 libraries/dlls, Right click the project -> Properties -> Build -> Platform target: x64.


       If using x86, the platform target should be x86.

Add the following C# demo code to your project.

// Set the training data path. Please put eng.traineddata (for English) under the directory you specified.

REImage img = new REImage(@"C:\page.jpeg");

// Resize image to improve accuracy. If the image is clear enough, skip this.
img = img.Resize(new Size((int)img.Width * 2, (int)img.Height * 2));

// Recognize  characters from this image. Default language is English.
OCRPage page = OCRHandler.Import(img);



Deploy OCR SDK into IIS Server

If you want to deploy your ASP.NET application that is compiled with our XImage.OCR for .NET into IIS server, you may do as follows.

Add Resources;

    Add the above eight DLLs to your C# project as references. For different file types recognition (like Tiff and Image), please add respective DLLs as well;

          What's more, add the reference RasterEdge.XDoc.TIFF.dll to the project is necessary to ocr text from tiff image file.

    Prepare source file for OCR language.

Call the server side method;

// Set the training data path. Please put eng.traineddata (for English) under the directory you specified.
//Set the languages used to extract text from image file.
List<Language> langs = new List<Language>();
OCRHandler.Settings.LanguagesEnabled = langs;

//Load tiff image file.
TIFFDocument doc = new TIFFDocument(@"C:\input.tif");
//Get page used to extract text.
TIFFPage page = (TIFFPage)doc.GetPage(0);
//Convert BasePage to bitmap.
//The default resolution is 96, if you set the resolution higher, it will be better to extract text from the image file.
Bitmap image = page.ConvertToImage(); //Convert to bitmap with default resolution.
//Bitmap image = page.ConvertToImage(); //Convert to bitmap with resolution = 192.
OCRPage ocrPage = OCRHandler.Import(image);
string text = ocrPage.GetText();

Deploy to IIS server.

    Open Internet Information Services Manager;

    Right-click "Sites" and select "Add Web Site";

    According to your situation, set "Site name", and set "Physical path" to the place where you store WebViewerDemo;

    Then, set "Port" that monitors the application;

    Click "ok" to complete deploy your project.

If you configure IIS to run and 500.19 error occurs, then it may be caused by:

Not registered the .NET Framework to the IIS. (One of reasons: install a .NET Framework before the installation of IIS.)

The site configured in IIS has no sufficient authority to operate. (Modify permission.)

Here are some solutions:

If your operation system is 64bit, please cd to C:\Windows\Microsoft.NET\Framework64\v2.0.50727,Command to re-register net framework to the iis:aspnet_regiis-i.

      If your operation system is 32bit, please cd to C:\Windows\Microsoft.NET\Framework\v2.0.50727,Command to re-register net framework to the iis:aspnet_regiis-i.

Right-click the correspond site-> Edit Permissions -> Security -> Group or user names -> Edit -> Add -> Add Everyone usersgiven Full Control permissions.

Example: OCR Integration into WebViewer on IIS Server

Add a reference called RasterEdge.XDoc.HTML5Viewer.dll to your C# project. Once you do this, dependencies will automatically be included in your project;

To use robust OCR functions in WebViewer on IIS server, C# users may add some JavsScript demo codes as below in Default.aspx;

var _tabFile = new ToolbarTab("File");
_tabFile.addCommand(new RECommand("ocr"));

Click "File" Tab, and you can find there is an OCR icon under the tab;

Deploy to IIS server like stated above.

Distribute OCR SDK with C# Windows Application

It's very easy to distribute OCR SDK for .NET with your C# Windows application. Three steps are included.

Firstly, please add the four indispensable DLLs to your C# Windows project as references. For different file types recognition (like Tiff and PDF), please also add respective DLLs;

Then, use their namespaces accordingly;

Copy C# demo code below to your own OCR method.

private void getPageOCRText(REImage image)
        OCRHandler.Settings.LanguagesEnabled = new List<Language>();
        OCRPage ocrPage = OCRHandler.Import(image);
        string text = ocrPage.GetText();


Copy Source folder from the download package to the same folder as added DLLs. Then, delete unnecessary font file. For instance, if you need English font, only "eng.traineddata" file should be remained.