Leadtools.Forms.Ocr Requires Document/Medical product license | Send comments on this topic. | Back to Introduction - All Topics | Help Version 16.5.9.25
CreateEngine Method
See Also  Example
Leadtools.Forms.Ocr Namespace > OcrEngineManager Class : CreateEngine Method



engineType
The engine type to use.
useThunkServer
true to use the LEADTOOLS thunk server when loading the internal engine, otherwise, false.
engineType
The engine type to use.
useThunkServer
true to use the LEADTOOLS thunk server when loading the internal engine, otherwise, false.
Creates an instance of IOcrEngine.

Syntax

Visual Basic (Declaration) 
Public Shared Function CreateEngine( _
   ByVal engineType As OcrEngineType, _
   ByVal useThunkServer As Boolean _
) As IOcrEngine
Visual Basic (Usage)Copy Code
Dim engineType As OcrEngineType
Dim useThunkServer As Boolean
Dim value As IOcrEngine
 
value = OcrEngineManager.CreateEngine(engineType, useThunkServer)
C# 
public static IOcrEngine CreateEngine( 
   OcrEngineType engineType,
   bool useThunkServer
)
C++/CLI 
public:
static IOcrEngine^ CreateEngine( 
   OcrEngineType engineType,
   bool useThunkServer
) 

Parameters

engineType
The engine type to use.
useThunkServer
true to use the LEADTOOLS thunk server when loading the internal engine, otherwise, false.

Return Value

The instance of IOcrEngine that this method creates.

Example

This example will use the LEADTOOLS OCR Plus engine to OCR an image and save it as a PDF file.

Visual BasicCopy Code
Public Sub CreateEngineExample()
   ' Unlock the support needed for LEADTOOLS Plus OCR engine
   RasterSupport.Unlock(RasterSupportType.Document, "Replace with your own key here")
   RasterSupport.Unlock(RasterSupportType.OcrPlus, "Replace with your own key here")
   RasterSupport.Unlock(RasterSupportType.OcrPlusPdfLeadOutput, "Replace with your own key here")
   ' Create an instance of the engine
   Using ocrEngine As IOcrEngine = OcrEngineManager.CreateEngine(OcrEngineType.Plus, False)
      ' Start the engine using default parameters
      ocrEngine.Startup(Nothing, Nothing, Nothing, Nothing)

      Dim tifFileName As String = LeadtoolsExamples.Common.ImagesPath.Path + "Ocr1.tif"
      Dim pdfFileName As String = LeadtoolsExamples.Common.ImagesPath.Path + "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
C#Copy Code
public void CreateEngineExample() 

   // Unlock the support needed for LEADTOOLS Plus OCR engine 
   RasterSupport.Unlock(RasterSupportType.Document, "Replace with your own key here"); 
   RasterSupport.Unlock(RasterSupportType.OcrPlus, "Replace with your own key here"); 
   RasterSupport.Unlock(RasterSupportType.OcrPlusPdfLeadOutput, "Replace with your own key here"); 
   // Create an instance of the engine 
   using(IOcrEngine ocrEngine = OcrEngineManager.CreateEngine(OcrEngineType.Plus, false)) 
   { 
      // Start the engine using default parameters 
      ocrEngine.Startup(null, null, null, null); 
 
      string tifFileName = LeadtoolsExamples.Common.ImagesPath.Path + "Ocr1.tif"; 
      string pdfFileName = LeadtoolsExamples.Common.ImagesPath.Path + "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(); 
   } 
}

Remarks

CreateEngine should be the first method your application calls into the Leadtools.Forms.Ocr assembly.

The CreateEngine method uses the .NET 2.0 Assembly.Load method to load the LEADTOOLS OCR assembly for the engine type. You cannot unload this assembly once it has been successfully loaded.

The various OCR engines provided by LEADTOOLS (except for the LEADTOOLS Advantage engine) are not thread safe. If your application requires multiple instances of IOcrEngine in separate threads or your application is server-based, then set the useThunkServer to true. The LEADTOOLS thunk server will be used in the background to ensure proper thread/process safety and cleanup. For more information, refer to LEADTOOLS OCR Thunk Server.

IMPORTANT: The above discussion is for the LEADTOOLS Plus and Professional engines only. The LEADTOOLS Advantage engine supports multi-threading and x64 platform natively and does not require the use of a "thunk server".

The engineType parameter determines which assembly will be loaded. For more information, refer to Files to be Included with Your Application.

The IOcrEngine interface also implements IDisposable. Dispose of the IOcrEngine instance when you are done using it.

Requirements

Target Platforms: Microsoft .NET Framework 3.0, Windows XP, Windows Server 2003 family, Windows Server 2008 family

See Also

CreateEngine requires an OCR module license and unlock key. For more information, refer to: Imaging Pro/Document/Medical Features