←Select platform

CreateEngine Method

Summary

Creates an instance of IOcrEngine.

Syntax
C#
VB
Objective-C
C++
Java
public static IOcrEngine CreateEngine( 
   OcrEngineType engineType, 
   bool useThunkServer 
) 
Public Shared Function CreateEngine( _ 
   ByVal engineType As OcrEngineType, _ 
   ByVal useThunkServer As Boolean _ 
) As IOcrEngine 
+ (LTOcrEngine *)createEngine:(LTOcrEngineType)engineType 
public static OcrEngine createEngine(OcrEngineType engineType) 
public: 
static IOcrEngine^ CreateEngine(  
   OcrEngineType engineType, 
   bool useThunkServer 
)  

Parameters

engineType
An OcrEngineType enumeration member that specifies the LEADTOOLS OCR engine type to use.

useThunkServer
This parameter is ignored since all LEADTOOLS OCR engines (LEAD, OmniPage, and Arabic) are now thread-safe and no longer require the "THUNK" server. Refer to Multi-Threading with LEADTOOLS OCR for more information.

Return Value

The IOcrEngine instance that this method creates.

Remarks

CreateEngine should be the first method your application calls into the Leadtools.Ocr assembly. Afterwards, you can use the properties and methods of this interface to perform your OCR tasks.

Based on the engine type passed to the CreateEngine methods, OcrEngineManager will load the OCR engine defined in one of the supporting assemblies and return an interface to IOcrEngine. Use this interface and its included types to start using the Leadtools.Ocr class library. For more information about the engine types, refer to OcrEngineType.

The CreateEngine method lets you create an instance of IOcrEngine, loading the corresponding Leadtools.Ocr.[EngineName].dll assembly using the .NET System.Reflection.Assembly.Load(string assemblyString) method. You cannot unload this assembly once it has been successfully loaded.

All LEADTOOLS OCR engines (LEAD, OmniPage, and Arabic) are now thread-safe and no longer require the "THUNK" server. Consequently, the useThunkServer parameter of the CreateEngine method will be ignored at all times for all engines.

Example

This example will use the LEADTOOLS OCR Module - LEAD Engine to OCR an image and save it as a PDF file.

C#
VB
using Leadtools; 
using Leadtools.Ocr; 
using Leadtools.Document.Writer; 
 
public void CreateEngineExample() 
{ 
   // Create an instance of the engine 
   using (IOcrEngine ocrEngine = OcrEngineManager.CreateEngine(OcrEngineType.LEAD, false)) 
   { 
      // Start the engine using default parameters 
      ocrEngine.Startup(null, null, null, LEAD_VARS.OcrLEADRuntimeDir); 
 
      string tifFileName = Path.Combine(LEAD_VARS.ImagesDir, "Ocr1.tif"); 
      string pdfFileName = Path.Combine(LEAD_VARS.ImagesDir, "Ocr1.pdf"); 
 
      // Create an OCR document 
      using (IOcrDocument ocrDocument = ocrEngine.DocumentManager.CreateDocument()) 
      { 
         // Add a page to the document 
         IOcrPage ocrPage = ocrDocument.Pages.AddPage(tifFileName, null); 
 
         // Recognize the page 
         // Note, Recognize can be called without calling AutoZone or manually adding zones. The engine will 
         // check and automatically auto-zones the page 
         ocrPage.Recognize(null); 
 
         // Save the document we have as PDF 
         ocrDocument.Save(pdfFileName, DocumentFormat.Pdf, null); 
      } 
 
      // Shutdown the engine 
      // Note: calling Dispose will also automatically shutdown the engine if it has been started 
      ocrEngine.Shutdown(); 
   } 
} 
 
static class LEAD_VARS 
{ 
   public const string ImagesDir = @"C:\Users\Public\Documents\LEADTOOLS Images"; 
   public const string OcrLEADRuntimeDir = @"C:\LEADTOOLS 20\Bin\Common\OcrLEADRuntime"; 
} 
Imports Leadtools 
Imports Leadtools.Ocr 
Imports Leadtools.Document.Writer 
 
Public Sub CreateEngineExample() 
   ' Create an instance of the engine 
   Using ocrEngine As IOcrEngine = OcrEngineManager.CreateEngine(OcrEngineType.LEAD, False) 
      ' Start the engine using default parameters 
      ocrEngine.Startup(Nothing, Nothing, Nothing, LEAD_VARS.OcrLEADRuntimeDir) 
 
      Dim tifFileName As String = Path.Combine(LEAD_VARS.ImagesDir, "Ocr1.tif") 
      Dim pdfFileName As String = Path.Combine(LEAD_VARS.ImagesDir, "Ocr1.pdf") 
 
      ' Create an OCR document 
      Using ocrDocument As IOcrDocument = ocrEngine.DocumentManager.CreateDocument() 
         ' Add a page to the document 
         Dim ocrPage As IOcrPage = ocrDocument.Pages.AddPage(tifFileName, Nothing) 
 
         ' Recognize the page 
         ' Note, Recognize can be called without calling AutoZone or manually adding zones. The engine will 
         ' check and automatically auto-zones the page 
         ocrPage.Recognize(Nothing) 
 
         ' Save the document we have as PDF 
         ocrDocument.Save(pdfFileName, DocumentFormat.Pdf, Nothing) 
      End Using 
 
      ' Shutdown the engine 
      ' Note: calling Dispose will also automatically shutdown the engine if it has been started 
      ocrEngine.Shutdown() 
   End Using 
End Sub 
 
Public NotInheritable Class LEAD_VARS 
   Public Const ImagesDir As String = "C:\Users\Public\Documents\LEADTOOLS Images" 
   Public Const OcrLEADRuntimeDir As String = "C:\LEADTOOLS 20\Bin\Common\OcrLEADRuntime" 
End Class 

Requirements

Target Platforms

Help Version 20.0.2020.4.2
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2020 LEAD Technologies, Inc. All Rights Reserved.

Leadtools.Ocr Assembly