Leadtools.Forms.Ocr Requires Document/Medical product license | Send comments on this topic. | Back to Introduction - All Topics | Help Version 16.5.9.25
IOcrAutoRecognizeManager Interface
See Also  Members   Example
Leadtools.Forms.Ocr Namespace : IOcrAutoRecognizeManager Interface



Provides support for the one shot "fire and forget" approach to OCR.

Syntax

Visual Basic (Declaration) 
Public Interface IOcrAutoRecognizeManager 
Visual Basic (Usage)Copy Code
Dim instance As IOcrAutoRecognizeManager
C# 
public interface IOcrAutoRecognizeManager 
C++/CLI 
public interface class IOcrAutoRecognizeManager 

Example

This example will convert TIF files in a source folder to PDF in a destination folder

Visual BasicCopy Code
Public Sub AutoRecognizeExample()
   ' 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")
   Console.WriteLine("Preparing the source and destination directories...")

   Dim sourceDirectory As String = LeadtoolsExamples.Common.ImagesPath.Path
   Dim destinationDirectory As String = LeadtoolsExamples.Common.ImagesPath.Path + "Destination"

   ' Prepare the directories
   If (Directory.Exists(sourceDirectory)) Then
      Directory.Delete(sourceDirectory, True)
   End If
   Directory.CreateDirectory(sourceDirectory)

   If (Directory.Exists(destinationDirectory)) Then
      Directory.Delete(destinationDirectory, True)
   End If
   Directory.CreateDirectory(destinationDirectory)

   ' Copy some files to the source directory
   Dim imagesDirectory As String = LeadtoolsExamples.Common.ImagesPath.Path

   For i As Integer = 0 To 3
      Dim fileName As String = String.Format("Ocr{0}.tif", i + 1)
      Dim sourceFileName As String = Path.Combine(imagesDirectory, fileName)
      Dim destinationFileName As String = Path.Combine(sourceDirectory, fileName)
      File.Copy(sourceFileName, destinationFileName, True)
   Next

   Console.WriteLine("Creating an instance of the engine...")

   ' Create an instance of the engine
   Using ocrEngine As IOcrEngine = OcrEngineManager.CreateEngine(OcrEngineType.Plus, False)
      ' Start the engine using default parameters
      Console.WriteLine("Starting up the engine...")
      ocrEngine.Startup(Nothing, Nothing, Nothing, Nothing)

      Dim ocrAutoRecognizeManager As IOcrAutoRecognizeManager = ocrEngine.AutoRecognizeManager

      ' Loop through all the TIF files in the source directory, convert to PDF in the destination directory
      Dim tifFileNames() As String = Directory.GetFiles(sourceDirectory, "*.tif")
      For Each tifFileName As String In tifFileNames
         ' Construct the name of the document file
         Dim documentFileName As String = Path.Combine(destinationDirectory, Path.GetFileNameWithoutExtension(tifFileName))
         documentFileName = Path.ChangeExtension(documentFileName, "pdf")

         ' OCR the file
         Console.WriteLine("Processing {0}", tifFileName)
         ocrAutoRecognizeManager.Run(tifFileName, documentFileName, Nothing, DocumentFormat.Pdf, Nothing)
         Console.WriteLine("Saved: {0}", documentFileName)
      Next

      ' Note: calling Dispose will also automatically shutdown the engine if it has been started
      Console.WriteLine("Shutting down...")
      ocrEngine.Shutdown()
   End Using
End Sub
C#Copy Code
public void AutoRecognizeExample() 

   // 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"); 
   Console.WriteLine("Preparing the source and destination directories..."); 
 
   string sourceDirectory = LeadtoolsExamples.Common.ImagesPath.Path; 
   string destinationDirectory = LeadtoolsExamples.Common.ImagesPath.Path + "Destination"; 
 
   // Prepare the directories 
   if(Directory.Exists(sourceDirectory)) 
      Directory.Delete(sourceDirectory, true); 
   Directory.CreateDirectory(sourceDirectory); 
 
   if(Directory.Exists(destinationDirectory)) 
      Directory.Delete(destinationDirectory, true); 
   Directory.CreateDirectory(destinationDirectory); 
 
   // Copy some files to the source directory 
   string imagesDirectory = LeadtoolsExamples.Common.ImagesPath.Path; 
 
   for(int i = 0; i < 4; i++) 
   { 
      string fileName = string.Format("Ocr{0}.tif", i + 1); 
      string sourceFileName = Path.Combine(imagesDirectory, fileName); 
      string destinationFileName = Path.Combine(sourceDirectory, fileName); 
      File.Copy(sourceFileName, destinationFileName, true); 
   } 
 
   Console.WriteLine("Creating an instance of the engine..."); 
 
   // Create an instance of the engine 
   using(IOcrEngine ocrEngine = OcrEngineManager.CreateEngine(OcrEngineType.Plus, false)) 
   { 
      // Start the engine using default parameters 
      Console.WriteLine("Starting up the engine..."); 
      ocrEngine.Startup(null, null, null, null); 
 
      IOcrAutoRecognizeManager ocrAutoRecognizeManager = ocrEngine.AutoRecognizeManager; 
 
      // Loop through all the TIF files in the source directory, convert to PDF in the destination directory 
      string[] tifFileNames = Directory.GetFiles(sourceDirectory, "*.tif"); 
      foreach(string tifFileName in tifFileNames) 
      { 
         // Construct the name of the document file 
         string documentFileName = Path.Combine(destinationDirectory, Path.GetFileNameWithoutExtension(tifFileName)); 
         documentFileName = Path.ChangeExtension(documentFileName, "pdf"); 
 
         // OCR the file 
         Console.WriteLine("Processing {0}", tifFileName); 
         ocrAutoRecognizeManager.Run(tifFileName, documentFileName, null, DocumentFormat.Pdf, null); 
         Console.WriteLine("Saved: {0}", documentFileName); 
      } 
 
      // Note: calling Dispose will also automatically shutdown the engine if it has been started 
      Console.WriteLine("Shutting down..."); 
      ocrEngine.Shutdown(); 
   } 
}

Remarks

You can access the instance of the IOcrAutoRecognizeManager used by an IOcrEngine through the IOcrEngine.AutoRecognizeManager property.

The methods of this interface will let you create a document from an image file on disk with optional progress and status monitors.

You can use the Run method to convert in one line of code an image on disk to a final document with any of the document formats supported by this IOcrEngine.

Requirements

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

See Also

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