L_OcrAutoRecognizeManager_SetJobOperationCallback

#include "ltocr.h"

L_LTOCR_API L_INT EXT_FUNCTION L_OcrAutoRecognizeManager_SetJobOperationCallback(autoRecognizeManager, callback, userData)

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

Parameters

L_OcrAutoRecognizeManager autoRecognizeManager

Handle to the OCR engine auto recognize manager.

L_OcrAutoRecognizeJobOperationCallback callback

Pointer to L_OcrAutoRecognizeJobOperationCallback function to get called while job is running.

L_VOID* userData

Optional user data to pass to the callback function.

Returns

Value Meaning
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

See Also

Functions

Topics

Example

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 20.0.2020.4.2
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2020 LEAD Technologies, Inc. All Rights Reserved.

LEADTOOLS OCR Module - LEAD Engine C API Help