Working with Recognition Results Using OCR Plus

To add code to an existing project in order to work with recognition results:

1.

Start with the program you created in Recognize Pages.

2.

Define the following global IDs in Ezfunc.h in the OCR_Ltdoc directory:

#define IDM_GET_OUTPUTFORMAT        207
#define IDM_SAVE_RESULTS            208

3.

Edit EZFUNC.RC file in the OCR_Ltdoc directory and add the following lines:

 

MAIN_MENU   MENU
BEGIN
   ... 
   ... 
   MENUITEM "Get Output Formats"    IDM_GET_OUTPUTFORMAT
   MENUITEM "Save Results"          IDM_SAVE_RESULTS
END

4.

In the MainWndProc procedure, add the following code to the switch statement for WM_COMMAND:

      case IDM_GET_OUTPUTFORMAT:
         {
            nRet = L_DocEnumOutputFileFormats(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:
         {
            RESULTOPTIONS ResOpts;

            memset(&ResOpts, 0, sizeof(RESULTOPTIONS));
            nRet = L_DocGetRecognitionResultOptions(hDoc, &ResOpts, sizeof(RESULTOPTIONS));
            if (nRet == SUCCESS)
            {
               ResOpts.Format = DOC_WORD_97_2000_XP;
               ResOpts.FormatLevel = FORMAT_LEVEL_FULL;

               L_DocSetRecognitionResultOptions(hDoc, &ResOpts);
               nRet = L_DocSaveResultsToFile (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;

5.

Add the following function to the end of the code in EZFUNC.CPP:

L_INT EXT_CALLBACK EnumOutputFileFormatsCB(FORMAT_TYPE Format, L_VOID * pUserData)
{
   UNREFERENCED_PARAMETER(pUserData);

   TEXTFORMATINFO FormatInfo;
   L_INT nRet;
   L_TCHAR szBuffer[1024];

   memset(&FormatInfo, 0, sizeof(TEXTFORMATINFO));
   nRet = L_DocGetTextFormatInfo(hDoc, Format, &FormatInfo, sizeof(TEXTFORMATINFO));
   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;
}

 

6.

Also, add the following statement before the MainWndProc function

L_INT EXT_CALLBACK EnumOutputFileFormatsCB(FORMAT_TYPE Format, L_VOID * pUserData);

 

7.

Build SimpleLoad.exe.

8.

Run SimpleLoad.exe.