←Select platform

OcrAutoRecognizeJobOperationEventArgs Class

Summary

Contains data for the IOcrAutoRecognizeManager.JobOperation event.

Syntax
C#
VB
Objective-C
C++
Java
[SerializableAttribute()] 
public class OcrAutoRecognizeJobOperationEventArgs : EventArgs 
<SerializableAttribute()> 
Public Class OcrAutoRecognizeJobOperationEventArgs  
   Inherits System.EventArgs 
@interface LTOcrAutoRecognizeJobOperationEventArgs : NSObject 
public class OcrAutoRecognizeJobOperationEvent extends EventObject 
[SerializableAttribute()] 
public ref class OcrAutoRecognizeJobOperationEventArgs : public System.EventArgs  

Remarks

IOcrAutoRecognizeManager.JobOperation will trigger when Run, RunJob or RunJobAsync is called.

You can use this event to get information on the current operation (creating an OCR document, loading a page, zoning, recognizing, saving, etc.).

This class contains the following members:

Member Description
Status The status of the job. You can set this from the default value of OcrAutoRecognizeManagerJobStatus.Success to OcrAutoRecognizeManagerJobStatus.Abort to abort the recognition process.
Job The instance of the IOcrAutoRecognizeJob currently being run. You can use this member to get information about the job, for example, the image file name and page numbers to recognize and the output document file name and format through IOcrAutoRecognizeJob.JobData. Note that OcrAutoRecognizeJobData.LastPageNumber will have the true value of the last page number in the image file if a value of -1 (for up to last page) was passed in the original object used to create IOcrAutoRecognizeJob.
PostOperation A boolean value that indicates whether the engine is preparing to run the operation (the value of PostOperation is false) or whether the operation has already run (the value of PostOperation is true). This is useful if you want to manipulate operation data as shown in the example.
Operation An OcrAutoRecognizeManagerJobOperation enumeration member that specifies the current operation.
Document An IOcrDocument instance that specifies the OCR document being used in the current operation. This object is not valid and will be null (Nothing in Visual Basic) when the current operation is ConvertDocument (or in CreateDocument with PostOperation equals to false).
Page an IOcrPage instance that specifies the OCR page being used in the current operation. This object is not valid and will be null (Nothing in Visual Basic) when the current operation is CreateDocument, PrepareDocument, SaveDocument or ConvertDocument.
ImagePageNumber The page number in the input (image) file name for the current operation. This member is not valid and will be 0 when the current operation is CreateDocument, PrepareDocument, SaveDocument or ConvertDocument.
PageImage The raster image object used for the current operation. This member is only valid when the current operation is LoadPage and SavePage.
LtdFileName The name of the LEAD Temporary Document (LTD) being used in the current operation. Depending on how the IOcrAutoRecognizeManager was setup, the engine might create LTD files during the recognition process to support multi-threading or recognition of images with large amount of pages. The value of this member is valid only when the current operation is SavePage (as the LTD for this page), AppendLtd (as the source file name) or ConvertDocument (as the source file name).
Format An DocumentFormat enumeration member that specifies the format being used in the current operation. This member will be equal to the original OcrAutoRecognizeJobData.Format value except for the following operations: SavePage and AppendLtd where it will be DocumentFormat.Ltd or SaveDocument where it can either be the original format or DocumentFormat.Ltd if LTD is being used to create a temporary document during recognition.
DocumentFileName The name of the document file being saved in the current operation. This member will be equal to the original OcrAutoRecognizeJobData.DocumentFileName value except for the following operations: SavePage and AppendLtd where it will be destination file name or SaveDocument where it can either be the original document file name or the name of a temporary LTD file if LTD is being used to create a temporary document during recognition.
DocumentWriterInstance The DocumentWriter instance being used in the current operation. This member will be equal to IOcrDocument.DocumentWriterInstance in all operations where an Document is available. When the operation is ConvertDocument, this instance will point to the DocumentWriter object being used to convert the document.

Example

This example will use the IOcrAutoRecognizeManager.JobOperation to change the zones of a document being recognized with IOcrAutoRecognizeManager.RunJob.

C#
VB
using Leadtools; 
using Leadtools.Codecs; 
using Leadtools.Ocr; 
using Leadtools.Document.Writer; 
using Leadtools.Forms.Common; 
using Leadtools.WinForms; 
 
public void JobOperationExample() 
{ 
   string imageFileName = Path.Combine(LEAD_VARS.ImagesDir, "Ocr1.tif"); 
   string documentFileName = Path.Combine(LEAD_VARS.ImagesDir, "JobOperation.pdf"); 
 
   using (IOcrEngine ocrEngine = OcrEngineManager.CreateEngine(OcrEngineType.LEAD, false)) 
   { 
      ocrEngine.Startup(null, null, null, LEAD_VARS.OcrLEADRuntimeDir); 
 
      IOcrAutoRecognizeManager autoRecognizeManager = ocrEngine.AutoRecognizeManager; 
      autoRecognizeManager.JobOperation += new EventHandler<OcrAutoRecognizeJobOperationEventArgs>(autoRecognizeManager_JobOperation); 
 
      IOcrAutoRecognizeJob job = autoRecognizeManager.CreateJob(new OcrAutoRecognizeJobData(imageFileName, DocumentFormat.Pdf, documentFileName)); 
      autoRecognizeManager.RunJob(job); 
 
      autoRecognizeManager.JobOperation -= new EventHandler<OcrAutoRecognizeJobOperationEventArgs>(autoRecognizeManager_JobOperation); 
   } 
} 
 
private static void autoRecognizeManager_JobOperation(object sender, OcrAutoRecognizeJobOperationEventArgs e) 
{ 
   // We did not pass a zone to the job, so the engine will attempt to do AutoZone unless we 
   // add any zone to the input document. 
   // We can also check for e.PostOperation equals to true and manipulate the zones 
   // found the engine at this point 
 
   // Add a graphics zone. 
   // If you comment out this code, the result PDF will contain text, but since we will be adding a zone here, 
   // the engine will not auto-zone the document for us. Also, since the zone we are adding is 
   // graphics that takes up the whole page, the result PDF will contain a raster image and no text. 
   if (!e.PostOperation && e.ImagePageNumber == 1) 
   { 
      OcrZone ocrZone = new OcrZone(); 
      ocrZone.ZoneType = OcrZoneType.Graphic; 
      ocrZone.Bounds = new LeadRect(0, 0, e.Page.Width, e.Page.Height); 
      e.Page.Zones.Add(ocrZone); 
   } 
} 
 
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.Codecs 
Imports Leadtools.Ocr 
Imports Leadtools.Document.Writer 
Imports Leadtools.Forms.Common 
Imports Leadtools.WinForms 
 
Public Sub JobOperationExample() 
   Dim imageFileName As String = Path.Combine(LEAD_VARS.ImagesDir, "Ocr1.tif") 
   Dim documentFileName As String = Path.Combine(LEAD_VARS.ImagesDir, "JobOperation.pdf") 
 
   Using ocrEngine As IOcrEngine = OcrEngineManager.CreateEngine(OcrEngineType.LEAD, False) 
      ocrEngine.Startup(Nothing, Nothing, Nothing, LEAD_VARS.OcrLEADRuntimeDir) 
 
      Dim autoRecognizeManager As IOcrAutoRecognizeManager = ocrEngine.AutoRecognizeManager 
      AddHandler autoRecognizeManager.JobOperation, AddressOf autoRecognizeManager_JobOperation 
 
      Dim job As IOcrAutoRecognizeJob = 
         autoRecognizeManager.CreateJob(New OcrAutoRecognizeJobData(imageFileName, DocumentFormat.Pdf, documentFileName)) 
      autoRecognizeManager.RunJob(job) 
 
      RemoveHandler autoRecognizeManager.JobOperation, AddressOf autoRecognizeManager_JobOperation 
   End Using 
End Sub 
 
Private Shared Sub autoRecognizeManager_JobOperation(sender As Object, e As OcrAutoRecognizeJobOperationEventArgs) 
   ' We did not pass a zone to the job, so the engine will attempt to do AutoZone unless we 
   ' add any zone to the input document. 
   ' We can also check for e.PostOperation equals to true and manipulate the zones 
   ' found the engine at this point 
 
   ' Add a graphics zone. 
   ' If you comment out this code, the result PDF will contain text, but since we will be adding a zone here, 
   ' the engine will not auto-zone the document for us. Also, since the zone we are adding is 
   ' graphics that takes up the whole page, the result PDF will contain a raster image and no text. 
   If Not e.PostOperation AndAlso e.ImagePageNumber = 1 Then 
      Dim ocrZone As New OcrZone() 
      ocrZone.ZoneType = OcrZoneType.Graphic 
      ocrZone.Bounds = New LeadRect(0, 0, e.Page.Width, e.Page.Height) 
      e.Page.Zones.Add(ocrZone) 
   End If 
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