To add code to an existing project in order to work with recognition results:
Start with the program you created in Recognize Pages.
Define the following global IDs in Ezfunc.h in the OCR_Ltdoc2 directory:
#define IDM_GET_OUTPUTFORMAT 207
#define IDM_SAVE_RESULTS 208
Edit EZFUNC.RC file in the OCR_Ltdoc2 directory and add the following lines:
MAIN_MENU MENU
BEGIN
...
...
MENUITEM "Get Output Formats" IDM_GET_OUTPUTFORMAT
MENUITEM "Save Results" IDM_SAVE_RESULTS
END
In the MainWndProc procedure, add the following code to the switch statement for WM_COMMAND:
case IDM_GET_OUTPUTFORMAT:
{
nRet = L_Doc2EnumOutputFileFormats(hDoc, EnumOutputFileFormatsCB, NULL);
if (nRet != SUCCESS)
{
wsprintf (achBuff, TEXT("Error %d enumerating available file formats"), nRet);
MessageBox (NULL, achBuff, TEXT("Error"), MB_OK);
}
}
break;
case IDM_SAVE_RESULTS:
{
RESULTOPTIONS2 ResOpts;
memset(&ResOpts, 0, sizeof(RESULTOPTIONS2));
nRet = L_Doc2GetRecognitionResultOptions(hDoc, &ResOpts, sizeof(RESULTOPTIONS2));
if (nRet == SUCCESS)
{
ResOpts.Format = DOC2_WORD_2000;
ResOpts.FormatLevel = DOC2_FORMAT_LEVEL_AUTO;
L_Doc2SetRecognitionResultOptions(hDoc, &ResOpts);
nRet = L_Doc2SaveResultsToFile (hDoc, TEXT("c:\\test.doc"));
if (nRet != SUCCESS)
{
wsprintf (achBuff, TEXT("Error %d in saving recognition results to a file"), nRet);
MessageBox (NULL, achBuff, TEXT("Error"), MB_OK);
}
}
}
break;
Add the following function at the end of the code in EZFUNC.CPP in OCR_Ltdoc2 directory.
L_INT EXT_CALLBACK EnumOutputFileFormatsCB(DOC2_FORMATTYPE Format, L_VOID * pUserData)
{
UNREFERENCED_PARAMETER(pUserData);
TEXTFORMATINFO2 FormatInfo;
L_INT nRet;
L_TCHAR szBuffer[1024];
memset(&FormatInfo, 0, sizeof(TEXTFORMATINFO2));
nRet = L_Doc2GetTextFormatInfo(hDoc, Format, &FormatInfo, sizeof(TEXTFORMATINFO2));
if (nRet == SUCCESS)
{
wsprintf(szBuffer, TEXT("Format Name = %s\nFormat DLL Name = %s\nFormat Ext Name = %s\n"),
(FormatInfo.pszName) ? FormatInfo.pszName : TEXT(" "),
(FormatInfo.pszDLLName) ? FormatInfo.pszDLLName : TEXT(" "),
(FormatInfo.pszExtName) ? FormatInfo.pszExtName : TEXT(" "));
MessageBox(NULL, szBuffer, TEXT("Format Info"), MB_OK);
if (FormatInfo.pszName)
GlobalFreePtr(FormatInfo.pszName);
if (FormatInfo.pszDLLName)
GlobalFreePtr(FormatInfo.pszDLLName);
if (FormatInfo.pszExtName)
GlobalFreePtr(FormatInfo.pszExtName);
}
return SUCCESS;
}
Also, add the following statement before the MainWndProc function.
L_INT EXT_CALLBACK EnumOutputFileFormatsCB(DOC2_FORMATTYPE Format, L_VOID * pUserData);
Build SimpleLoad.exe.
Run SimpleLoad.exe.