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.




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;


  RasterEdge.XImage.OCR.dll


  RasterEdge.XImage.OCR.Tesseract.dll


  RasterEdge.Imaging.Basic.dll


  RasterEdge.Imaging.Basic.Codec.dll


  RasterEdge.Imaging.Drawing.dll


  RasterEdge.Imaging.Font.dll


  RasterEdge.Imaging.Processing.dll


  RasterEdge.XImage.AdvancedCleanup.Core.dll


Use corresponding namespaces;


  using RasterEdge.XImage.OCR;


  using RasterEdge.Imaging.Raster.Core;


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.
            OCRHandler.SetTrainResourcePath(@"c:\source");

            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);
            page.Recognize();

            Console.WriteLine(page.GetText());


     



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;




OCRHandler.SetTrainResourcePath(@"C:\source\");
            List<Language> langs = new List<Language>();
            langs.Add(Language.Eng);
            OCRHandler.Settings.LanguagesEnabled = langs;

            TIFFDocument doc = new TIFFDocument(@"C:\input.tif");
            TIFFPage page = (TIFFPage)doc.GetPage(0);
            Bitmap image = page.ConvertToImage(2.0f);
            OCRPage ocrPage = OCRHandler.Import(image);
            ocrPage.Recognize();
            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"));
_viewerTopToolbar.addTab(_tabFile);




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>();
        OCRHandler.Settings.LanguagesEnabled.Add(Language.Eng);
        OCRPage ocrPage = OCRHandler.Import(image);
        ocrPage.Recognize();
        string text = ocrPage.GetText();
        Console.Writeline(text);
}


   


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.