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



data
An instance of the IOcrProgressData interface containing the progress callback data.
Monitors progress of OCR operations.

Syntax

Visual Basic (Declaration) 
Public Delegate Sub OcrProgressCallback( _
   ByVal data As IOcrProgressData _
) 
Visual Basic (Usage)Copy Code
Dim instance As New OcrProgressCallback(AddressOf HandlerMethod)
C# 
public delegate void OcrProgressCallback( 
   IOcrProgressData data
)
C++/CLI 
public delegate void OcrProgressCallback( 
   IOcrProgressData^ data
)

Parameters

data
An instance of the IOcrProgressData interface containing the progress callback data.

Example

This example will display a simple "Processing" Windows Forms dialog that can be used to show OCR operation progress as well as allow the user to abort the current operation. You can plug this dialog into your application and call it in response to user-interface commands that correspond to OCR operations.

Visual BasicCopy Code
' Text writer to save the log to
Private _log As StreamWriter
Public Sub OcrProgressCallbackExample()
   ' 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")

   Dim logFileName As String = LeadtoolsExamples.Common.ImagesPath.Path + "log.txt"
   Dim multiPageTifFileName As String = LeadtoolsExamples.Common.ImagesPath.Path + "Ocr.tif"
   Dim pdfFileName As String = LeadtoolsExamples.Common.ImagesPath.Path + "Ocr1.pdf"

   ' Create the log text writer
   _log = File.CreateText(logFileName)

   ' 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)

      ' Create an OCR document
      Using ocrDocument As IOcrDocument = ocrEngine.DocumentManager.CreateDocument()
         ' Add this image to the document
         _log.WriteLine("Adding the pages")
         _log.WriteLine("********************************")
         ocrDocument.Pages.AddPages(multiPageTifFileName, 1, -1, AddressOf MyOcrProgressCallback)

         ' Auto-recognize the zones in all the pages
         _log.WriteLine("Auto-zoning")
         _log.WriteLine("********************************")
         ocrDocument.Pages.AutoZone(AddressOf MyOcrProgressCallback)

         ' Recognize it and save it as PDF
         _log.WriteLine("Recognizing")
         _log.WriteLine("********************************")
         ocrDocument.Pages.Recognize(AddressOf MyOcrProgressCallback)
         _log.WriteLine("Saving to PDF")
         _log.WriteLine("********************************")
         ocrDocument.Save(pdfFileName, DocumentFormat.Pdf, AddressOf MyOcrProgressCallback)
      End Using

      ' Shutdown the engine
      ' Note: calling Dispose will also automatically shutdown the engine if it has been started
      ocrEngine.Shutdown()
   End Using

   _log.WriteLine("********************************")
   _log.WriteLine("Complete")
   _log.Flush()
   _log.Close()
End Sub

Private Sub MyOcrProgressCallback(ByVal data As IOcrProgressData)
   If (Data.Percentage = 0) Then
      _log.WriteLine("--------------------------")
   End If

   _log.WriteLine("Page:{0}({1}:{2}) {3}% Operation:{4}", _
      data.CurrentPageIndex.ToString("00"), _
      data.FirstPageIndex.ToString("00"), _
      data.LastPageIndex.ToString("00"), _
      data.Percentage.ToString("000"), _
      data.Operation)
End Sub
C#Copy Code
// Text writer to save the log to 
private StreamWriter _log; 
public void OcrProgressCallbackExample() 

   // 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"); 
 
   string logFileName = LeadtoolsExamples.Common.ImagesPath.Path + "log.txt"; 
   string multiPageTifFileName = LeadtoolsExamples.Common.ImagesPath.Path + "Ocr.tif"; 
   string pdfFileName = LeadtoolsExamples.Common.ImagesPath.Path + "Ocr1.pdf"; 
 
   // Create the log text writer 
   _log = File.CreateText(logFileName); 
 
   // 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); 
 
      // Create an OCR document 
      using(IOcrDocument ocrDocument = ocrEngine.DocumentManager.CreateDocument()) 
      { 
         // Add this image to the document 
         _log.WriteLine("Adding the pages"); 
         _log.WriteLine("********************************"); 
         ocrDocument.Pages.AddPages(multiPageTifFileName, 1, -1, new OcrProgressCallback(MyOcrProgressCallback)); 
 
         // Auto-recognize the zones in all the pages 
         _log.WriteLine("Auto-zoning"); 
         _log.WriteLine("********************************"); 
         ocrDocument.Pages.AutoZone(new OcrProgressCallback(MyOcrProgressCallback)); 
 
         // Recognize it and save it as PDF 
         _log.WriteLine("Recognizing"); 
         _log.WriteLine("********************************"); 
         ocrDocument.Pages.Recognize(new OcrProgressCallback(MyOcrProgressCallback)); 
         _log.WriteLine("Saving to PDF"); 
         _log.WriteLine("********************************"); 
         ocrDocument.Save(pdfFileName, DocumentFormat.Pdf, new OcrProgressCallback(MyOcrProgressCallback)); 
      } 
 
      // Shutdown the engine 
      // Note: calling Dispose will also automatically shutdown the engine if it has been started 
      ocrEngine.Shutdown(); 
   } 
 
   _log.WriteLine("********************************"); 
   _log.WriteLine("Complete"); 
   _log.Flush(); 
   _log.Close(); 

 
private void MyOcrProgressCallback(IOcrProgressData data) 

   if(data.Percentage == 0) 
      _log.WriteLine("--------------------------"); 
 
   _log.WriteLine("Page:{0}({1}:{2}) {3}% Operation:{4}", 
      data.CurrentPageIndex.ToString("00"), 
      data.FirstPageIndex.ToString("00"), 
      data.LastPageIndex.ToString("00"), 
      data.Percentage.ToString("000"), 
      data.Operation); 
}

Remarks

The OCR engine will continuously invoke the callback procedure during the different OCR operations with an instance of IOcrProgressData providing the current processing stage and a percentage indicator value. Use this function to indicate progress of application operations.

The callback can set the IOcrProgressData.Status property at any time to OcrProgressStatus.Abort to abort the OCR process and cancel all pending operations.

Requirements

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

See Also

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