L_OcrAutoRecognizeManager_SetJobOperationCallback

#include "ltocr.h"

L_LTOCR_API L_INT EXT_FUNCTION L_OcrAutoRecognizeManager_SetJobOperationCallback(autoRecognizeManager, callback, userData)

L_OcrAutoRecognizeManager autoRecognizeManager; handle to the OCR auto recognize manager
L_OcrAutoRecognizeJobOperationCallback callback; pointer to L_OcrAutoRecognizeJobOperationCallback function
L_VOID* userData; optional user data to pass to the callback function

Use this function to set a callback to get fired when any OCR job is running to get information on the current operation (creating an OCR document, loading a page, zoning, recognizing, saving, etc.).

Parameter Description
autoRecognizeManager Handle to the OCR engine auto recognize manager.
callback Pointer to L_OcrAutoRecognizeJobOperationCallback function to get called while job is running.
userData Optional user data to pass to the callback function.

Returns

SUCCESS The function was successful.
< 1 An error occurred. Refer to Return Codes.

Comments

Use this function to set a callback to get fired when any OCR job is running to get information on the current operation (creating an OCR document, loading a page, zoning, recognizing, saving, etc.).

This callback occurs while a job is running. For more information about the kind of information you will get during this callback, refer to L_OcrAutoRecognizeJobOperationCallbackData.

Required DLLs and Libraries

LTOCR
For a listing of the exact DLLs and Libraries needed, based on the toolkit version, refer to Files To Be Included With Your Application.
See Also
Functions: L_OcrAutoRecognizeManager_GetOptions, L_OcrAutoRecognizeManager_SetOptions, L_OcrAutoRecognizeManager_GetJobOperationCallback, L_OcrAutoRecognizeManager_GetRunJobCallback, L_OcrAutoRecognizeManager_SetRunJobCallback, L_OcrAutoRecognizeManager_CreateJob, L_OcrAutoRecognizeManager_RunJob, L_OcrAutoRecognizeManager_RunJobAsync, L_OcrAutoRecognizeManager_AbortAllJobs, L_OcrAutoRecognizeManager_Run
Topics: Programming with LEADTOOLS OCR Advantage
Starting and Shutting Down the OCR Engine
Recognizing OCR Pages
Working With OCR Pages

Example

#define MAKE_IMAGE_PATH(pFileName) TEXT("C:\\Users\\Public\\Documents\\LEADTOOLS Images\\")pFileName 
#define OCR_ADVANTAGE_RUNTIME_DIR TEXT("C:\\LEADTOOLS 19\\Bin\\Common\\OcrAdvantageRuntime") 
L_INT EXT_CALLBACK runJobOperationCB(const L_OcrAutoRecognizeJobOperationCallbackData* data, L_VOID* /*userData*/) 
{ 
   // We did not pass a zone to the job, so the engine will attempt to do L_OcrPagge_AutoZone unless we 
   // add any zone to the input document. 
   // We can also check for data->IsPostOperation equals to L_TRUE and manipulate the zones 
   // found by the engine at this point 
   if(!data->IsPostOperation && data->ImagePageNumber == 1) 
   { 
      //Debug information 
      switch(data->Operation) 
      { 
         case L_OcrAutoRecognizeManagerJobOperation_Other: 
         std::wcout << L"DEBUG --RunJobCB operation: JobOperation_Other" << std::endl; 
         break; 
         case L_OcrAutoRecognizeManagerJobOperation_CreateDocument: 
         std::wcout << L"DEBUG --RunJobCB operation: JobOperation_CreateDocument" << std::endl; 
         break; 
         case L_OcrAutoRecognizeManagerJobOperation_LoadPage: 
         std::wcout << L"DEBUG --RunJobCB operation: JobOperation_LoadPage" << std::endl; 
         break; 
         case L_OcrAutoRecognizeManagerJobOperation_PreprocessPage: 
         std::wcout << L"DEBUG --RunJobCB operation: JobOperation_PreprocessPage" << std::endl; 
         break; 
         case L_OcrAutoRecognizeManagerJobOperation_ZonePage: 
         std::wcout << L"DEBUG --RunJobCB operation: JobOperation_ZonePage" << std::endl; 
         break; 
         case L_OcrAutoRecognizeManagerJobOperation_RecognizePage: 
         std::wcout << L"DEBUG --RunJobCB operation: JobOperation_RecognizePage" << std::endl; 
         break; 
         case L_OcrAutoRecognizeManagerJobOperation_SavePage: 
         std::wcout << L"DEBUG --RunJobCB operation: JobOperation_SavePage" << std::endl; 
         break; 
         case L_OcrAutoRecognizeManagerJobOperation_Append: 
         std::wcout << L"DEBUG --RunJobCB operation: JobOperation_Append" << std::endl; 
         break; 
         case L_OcrAutoRecognizeManagerJobOperation_ConvertDocument: 
         std::wcout << L"DEBUG --RunJobCB operation: JobOperation_ConvertDocument" << std::endl; 
         break; 
      } 
      //end debug info 
      // 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(data->PageBitmap != NULL && data->Operation == L_OcrAutoRecognizeManagerJobOperation_LoadPage) 
      { 
         L_RECT rect = {0, 0, data->PageBitmap->Width, data->PageBitmap->Height}; 
         L_OcrZone ocrZone = { 0 }; 
         L_OcrZone_Default(&ocrZone); 
         ocrZone.ZoneType = L_OcrZoneType_Graphic; 
         ocrZone.Bounds = rect; 
         L_UINT count = 0; 
         L_OcrPage_GetZoneCount(data->Page, &count); 
         std::wcout << L"DEBUG -- Zone count: " << count << std::endl; //Debug output 
         if(data->Page != NULL) 
         { 
            L_OcrPage_AddZone(data->Page, &ocrZone); 
            std::wcout << L"DEBUG -- Single zone inserted" << std::endl; //Debug output 
            L_OcrPage_GetZoneCount(data->Page, &count); 
            std::wcout << L"DEBUG -- Zone count after inserting zone: " << count << std::endl; //Debug output 
         } 
         else 
            std::wcout << L"DEBUG -- OCR page is NULL: " << count << std::endl; //Debug output 
      } 
   } 
   return SUCCESS; 
} 
L_INT L_OcrAutoRecognizeManager_SetJobOperationCallbackExample() 
{ 
   L_INT retCode = -1; 
   L_OcrEngine ocrEngine = NULL; 
   L_OcrAutoRecognizeManager autoRecognizeManager = NULL; 
   L_OcrAutoRecognizeJob autoRecognizeJob = NULL; 
   retCode = L_OcrEngineManager_CreateEngine(L_OcrEngineType_Advantage, &ocrEngine); 
   if(retCode != SUCCESS) 
      return retCode; 
   // Start the engine using default parameters 
   retCode = L_OcrEngine_Startup(ocrEngine, NULL, OCR_ADVANTAGE_RUNTIME_DIR); 
   if(retCode != SUCCESS) 
      return retCode; 
   L_OcrEngine_GetAutoRecognizeManager(ocrEngine, &autoRecognizeManager); 
   L_OcrAutoRecognizeJobOperationCallback jobOperationCallback; 
   L_OcrAutoRecognizeManager_GetJobOperationCallback(autoRecognizeManager, &jobOperationCallback, NULL); 
   if(jobOperationCallback == NULL) 
   { 
      // Run the job in a thread and wait for it to be done 
      // We will use the callback to get notified when the job is finished 
      L_OcrAutoRecognizeManager_SetJobOperationCallback(autoRecognizeManager, &runJobOperationCB, NULL); 
   } 
   L_OcrAutoRecognizeJobData jobData = {0}; 
   jobData.StructSize = sizeof(L_OcrAutoRecognizeJobData); 
   wcscpy_s(jobData.ImageFileName, MAKE_IMAGE_PATH(L_TEXT("OCR1.tif"))); 
   wcscpy_s(jobData.DocumentFileName, MAKE_IMAGE_PATH(L_TEXT("OCR1.pdf"))); 
   jobData.Format = DOCUMENTFORMAT_PDF; 
   wcscpy_s(jobData.JobName, L"MyJob"); 
   jobData.FirstPageNumber = 1; 
   jobData.LastPageNumber = -1; 
   jobData.UserData = NULL; 
   wcscpy_s(jobData.ZonesFileName, L_TEXT("")); 
   L_OcrAutoRecognizeManager_CreateJob(autoRecognizeManager, &autoRecognizeJob, &jobData); 
   retCode = L_OcrAutoRecognizeManager_RunJob(autoRecognizeManager, autoRecognizeJob); 
   //CLEANUP 
   L_OcrAutoRecognizeJob_Destroy(autoRecognizeJob); 
   L_OcrEngine_Destroy(ocrEngine); 
   return retCode; 
} 

Help Version 19.0.2017.10.27
Products | Support | Contact Us | Copyright Notices
© 1991-2017 LEAD Technologies, Inc. All Rights Reserved.
LEADTOOLS Advantage OCR C API Help