L_OcrAutoRecognizeManager_SetRunJobCallback

#include "ltocr.h"

L_LTOCR_API L_INT EXT_FUNCTION L_OcrAutoRecognizeManager_SetRunJobCallback(autoRecognizeManager, callback, userData)

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

Use this function to set a callback to get notified when a job is about to start or when a job is completed or aborted.

Parameter Description
autoRecognizeManager Handle to the OCR engine auto recognize manager.
callback Pointer to L_OcrAutoRecognizeRunJobCallback function to get notified when a job is about to start or when a job is completed or aborted.
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 notified when a job is about to start or when a job is completed or aborted.

This callback occurs when a job is about to start or when a job is completed or aborted. For more information about the kind of information you will get during this callback, refer to L_OcrAutoRecognizeRunJobCallbackData.

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_SetJobOperationCallback, L_OcrAutoRecognizeManager_GetRunJobCallback, 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") 
const L_TCHAR* _ocrOperationNames[] = 
{ 
   L"LoadImage", 
   L"SaveImage", 
   L"PreprocessImage", 
   L"AutoZone", 
   L"Recognize", 
   L"SaveDocumentPrepare", 
   L"SaveDocument", 
   L"SaveDocumentConvertImage", 
   L"Formatting", 
   L"RecognizeOMR", 
}; 
L_VOID ShowJobErrors(L_OcrAutoRecognizeJob ocrJob) 
{ 
   // Show the errors 
   L_OcrAutoRecognizeManagerJobError* errors = NULL; 
   L_UINT errorCount = 0; 
   L_OcrAutoRecognizeJob_GetErrors(ocrJob, &errors, &errorCount); 
   std::wcout << L"Errors:" << std::endl; 
   for(L_UINT i = 0; i < errorCount; i++) 
   { 
      const L_OcrAutoRecognizeManagerJobError* error = &errors[i]; 
      std::wcout << L"  page: " << error->ImagePageNumber << L" Operation: " << _ocrOperationNames[error->Operation] << L" code: " << error->ErrorCode << std::endl; 
   } 
   L_OcrMemory_Free(errors); 
} 
L_INT EXT_CALLBACK MyRunJobCB(const L_OcrAutoRecognizeRunJobCallbackData* data, L_VOID* /*userData*/) 
{ 
   std::wcout << L"MyRunJobCallback fired...\nStatus: " << data->Status << std::endl; 
   if(data->IsCompleted) 
      std::wcout << L"Job completed" << std::endl; 
   else 
      std::wcout << L"Job still in progress" << std::endl; 
   if(data->Status != SUCCESS) 
      ShowJobErrors(data->Job); 
   return SUCCESS; 
} 
L_INT L_OcrAutoRecognizeManager_SetRunJobCallbackExample() 
{ 
   L_INT retCode = -1; 
   L_OcrEngine ocrEngine = NULL; 
   L_OcrAutoRecognizeManager autoRecognizeManager = NULL; 
   L_OcrAutoRecognizeManagerOptions autoRecognizeOptions = { 0 }; 
   L_OcrAutoRecognizeJob autoRecognizeJob = NULL; 
   // Create an instance of the engine 
   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; 
   // Get the AutoRecognizeManager 
   L_OcrEngine_GetAutoRecognizeManager(ocrEngine, &autoRecognizeManager); 
   // Set the options we want 
   autoRecognizeOptions.StructSize = sizeof(L_OcrAutoRecognizeManagerOptions); 
   L_OcrAutoRecognizeManager_GetOptions(autoRecognizeManager, &autoRecognizeOptions); 
   // Use maximum CPUs/cores of current machine to speed up recognition 
   autoRecognizeOptions.UseThreads = true; 
   // Deskew and auto-orient all pages before recognition 
   autoRecognizeOptions.PreprocessPageCommands = L_OcrAutoPreprocessPageCommands_Deskew | L_OcrAutoPreprocessPageCommands_Rotate; 
   // Give the manager our updated settings 
   L_OcrAutoRecognizeManager_SetOptions(autoRecognizeManager, &autoRecognizeOptions); 
   L_OcrAutoRecognizeJobData jobData; 
   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); 
   L_OcrAutoRecognizeRunJobCallback runJobCallback; 
   L_OcrAutoRecognizeManager_GetRunJobCallback(autoRecognizeManager, &runJobCallback, NULL); 
   if(runJobCallback == NULL) 
   { 
      // Add our callback handler 
      L_OcrAutoRecognizeManager_SetRunJobCallback(autoRecognizeManager, &MyRunJobCB, NULL); 
   } 
   // Run the job 
   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