// OCRFileView.cpp : implementation of the COCRFileView class // /****************************************** 1. Select File -> Open to load an image, load "OCR1.tif" 2. Select OCR -> "Add Page" to the loaded image into OCR engine 3. Select OCR -> "Recognize" to recognize the added page. 4. Select OCR -> "Save Results to All File Formats" to save the recognition results to all supported file formats. ******************************************/ #include "stdafx.h" #include "OCRFile.h" #include "OCRFileDoc.h" #include "OCRFileView.h" #include "windowsx.h" #include "EngineMsg.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // COCRFileView IMPLEMENT_DYNCREATE(COCRFileView, CScrollView) BEGIN_MESSAGE_MAP(COCRFileView, CScrollView) //{{AFX_MSG_MAP(COCRFileView) ON_WM_CREATE() ON_WM_DESTROY() ON_WM_ERASEBKGND() ON_MESSAGE(WM_DOREALIZE, OnDoRealize) ON_COMMAND(ID_FILE_OPEN, OnFileOpen) ON_COMMAND(ID_FILE_SAVE, OnFileSave) ON_UPDATE_COMMAND_UI(ID_FILE_SAVE, OnUpdateFileSave) ON_COMMAND(ID_OCR_ADDPAGE, OnOcrAddpage) ON_UPDATE_COMMAND_UI(ID_OCR_ADDPAGE, OnUpdateOcrAddpage) ON_COMMAND(ID_OCR_RECOGNIZE, OnOcrRecognize) ON_UPDATE_COMMAND_UI(ID_OCR_RECOGNIZE, OnUpdateOcrRecognize) ON_COMMAND(ID_OCR_SAVERESULTSTOALLFILEFORMATS, OnOcrSaveresultstoallfileformats) ON_UPDATE_COMMAND_UI(ID_OCR_SAVERESULTSTOALLFILEFORMATS, OnUpdateOcrSaveresultstoallfileformats) //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // COCRFileView construction/destruction COCRFileView::COCRFileView() { L_InitBitmap(&m_LEADBitmap, sizeof(BITMAPHANDLE), 0, 0, 0); m_hDoc = NULL; m_bPageAdded = FALSE; m_bRecog = FALSE; m_hZonePen = NULL; m_hSelZonePen = NULL; m_hPalette = NULL; } COCRFileView::~COCRFileView() { if (m_LEADBitmap.Flags.Allocated) L_FreeBitmap(&m_LEADBitmap); } BOOL COCRFileView::PreCreateWindow(CREATESTRUCT& cs) { // TODO: Modify the Window class or styles here by modifying // the CREATESTRUCT cs return CScrollView::PreCreateWindow(cs); } ///////////////////////////////////////////////////////////////////////////// // COCRFileView drawing void COCRFileView::OnDraw(CDC* pDC) { COCRFileDoc* pDoc = GetDocument(); ASSERT_VALID(pDoc); HPALETTE OldPalette = NULL; if (m_LEADBitmap.Flags.Allocated) { CRect rcDst; rcDst.SetRect(0, 0, BITMAPWIDTH(&m_LEADBitmap), BITMAPHEIGHT(&m_LEADBitmap)); CRect rcClip; if (m_hPalette) { OldPalette = ::SelectPalette(pDC->m_hDC, m_hPalette, TRUE); pDC->RealizePalette(); } pDC->GetClipBox(rcClip); if (m_bPageAdded) { if (m_hDoc && m_bPageAdded) { L_DocDrawPage(m_hDoc, pDC->GetSafeHdc(), 0, NULL, NULL, &rcDst, &rcClip, SRCCOPY, TRUE); } } else L_PaintDC(pDC->GetSafeHdc(), &m_LEADBitmap, NULL, NULL, &rcDst, &rcClip, SRCCOPY); if (OldPalette) ::SelectPalette(pDC->m_hDC, OldPalette, TRUE); } } void COCRFileView::OnInitialUpdate() { CScrollView::OnInitialUpdate(); CSize sizeTotal; // TODO: calculate the total size of this view sizeTotal.cx = sizeTotal.cy = 0; SetScrollSizes(MM_TEXT, sizeTotal); } ///////////////////////////////////////////////////////////////////////////// // COCRFileView printing BOOL COCRFileView::OnPreparePrinting(CPrintInfo* pInfo) { // default preparation return DoPreparePrinting(pInfo); } void COCRFileView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/) { // TODO: add extra initialization before printing } void COCRFileView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/) { // TODO: add cleanup after printing } ///////////////////////////////////////////////////////////////////////////// // COCRFileView diagnostics #ifdef _DEBUG void COCRFileView::AssertValid() const { CScrollView::AssertValid(); } void COCRFileView::Dump(CDumpContext& dc) const { CScrollView::Dump(dc); } COCRFileDoc* COCRFileView::GetDocument() // non-debug version is inline { ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(COCRFileDoc))); return (COCRFileDoc*)m_pDocument; } #endif //_DEBUG ///////////////////////////////////////////////////////////////////////////// // COCRFileView message handlers void COCRFileView::CleanOpenDlgParam(LPOPENDLGPARAMS pFOParam) { if (pFOParam && pFOParam->pFileData != NULL) { for (L_INT i=0; i < pFOParam->nNumOfFiles; i++) { if (pFOParam->pFileData[i].pBitmap) { if (pFOParam->pFileData[i].pBitmap->Flags.Allocated) L_FreeBitmap(pFOParam->pFileData[i].pBitmap); GlobalFreePtr(pFOParam->pFileData[i].pBitmap); } if (pFOParam->pFileData[i].pThumbnail) { if (pFOParam->pFileData[i].pThumbnail->Flags.Allocated) L_FreeBitmap(pFOParam->pFileData[i].pThumbnail); GlobalFreePtr(pFOParam->pFileData[i].pThumbnail); } if (pFOParam->pFileData[i].pFileInfo) GlobalFreePtr(pFOParam->pFileData[i].pFileInfo); } GlobalFreePtr(pFOParam->pFileData); pFOParam->pFileData = NULL; pFOParam->nNumOfFiles = 0; } } LONG COCRFileView::OnDoRealize(WPARAM wParam, LPARAM lParam) { UINT nColorsChanged = 0; if (!m_LEADBitmap.Flags.Allocated) return 0; if (lParam) { if (((HWND) wParam) == m_hWnd) return(FALSE); } if (m_hPalette != NULL) { DeleteObject(m_hPalette); m_hPalette = NULL; } CClientDC dc(this); m_hPalette = L_CreatePaintPalette(dc.m_hDC, &m_LEADBitmap); if (m_hPalette) { HPALETTE oldPalette = ::SelectPalette(dc.m_hDC, m_hPalette, (BOOL) lParam); nColorsChanged = RealizePalette(dc); if (nColorsChanged > 0) Invalidate(); ::SelectPalette(dc.m_hDC, oldPalette, TRUE); } return ((LRESULT) (BOOL) (nColorsChanged > 0)); } void COCRFileView::UpdateScrollView() { CSize sizeTotal; if (m_LEADBitmap.Flags.Allocated) { sizeTotal.cx = BITMAPWIDTH(&m_LEADBitmap); sizeTotal.cy = BITMAPHEIGHT(&m_LEADBitmap); OnDoRealize((WPARAM)AfxGetApp()->m_pMainWnd->m_hWnd, (LPARAM) FALSE); } else sizeTotal.cx = sizeTotal.cy = 0; SetScrollSizes(MM_TEXT, sizeTotal); RedrawWindow(); } void COCRFileView::OnActivateView(BOOL bActivate, CView* pActivateView, CView* pDeactiveView) { if (bActivate) OnDoRealize((WPARAM)AfxGetApp()->m_pMainWnd->m_hWnd, (LPARAM) FALSE); // same as SendMessage(WM_DOREALIZE); CScrollView::OnActivateView(bActivate, pActivateView, pDeactiveView); } int COCRFileView::OnCreate(LPCREATESTRUCT lpCreateStruct) { if (CScrollView::OnCreate(lpCreateStruct) == -1) return -1; if (L_IsSupportLocked(L_SUPPORT_OCR)) { AfxMessageBox(TEXT("You need to unlock the OCR engine before you can use this demo!")); return -1; } BeginWaitCursor(); L_INT nRet = L_DocStartUp(&m_hDoc); if (nRet == SUCCESS) { m_hZonePen = CreatePen(PS_SOLID, 2, RGB(128, 128, 128)); m_hSelZonePen = CreatePen(PS_SOLID, 2, RGB(0, 255, 255)); L_DocSetZonePen(m_hDoc, m_hZonePen); L_DocSetSelectedZonePen(m_hDoc, m_hSelZonePen); HKEY hKey = HKEY_LOCAL_MACHINE; L_TCHAR szSubKey[MAX_PATH]; memset(szSubKey, 0, sizeof(szSubKey)); #ifndef UNICODE strcpy(szSubKey, "SOFTWARE\\LEAD Technologies, Inc.\\Images"); #else lstrcpy(szSubKey, _T("SOFTWARE\\LEAD Technologies, Inc.\\UnicodeImages")); #endif LONG nRet = RegOpenKeyEx(hKey, szSubKey, 0, KEY_READ, &hKey); if (nRet == 0) { DWORD lpType; BYTE data[MAX_PATH]; DWORD sizeData = MAX_PATH; memset(data,0,sizeof(data)); nRet = RegQueryValueEx(hKey, _T(""), NULL, &lpType, data, &sizeData); if (nRet == 0) m_csImagesPath.Format(_T("%s"), (L_TCHAR *)&data); RegCloseKey(hKey); } } else { if (nRet != ERROR_DOC_INITIALIZE_ENGINE) AfxMessageBox(TEXT("Failed while initializing the OCR Engine")); else { CEngineMsg engineDlg; engineDlg.DoModal(); } return -1; } EndWaitCursor(); return 0; } void COCRFileView::OnDestroy() { if (m_LEADBitmap.Flags.Allocated) L_FreeBitmap(&m_LEADBitmap); if (m_hDoc) L_DocShutDown(&m_hDoc); if (m_hZonePen) { DeleteObject(m_hZonePen); m_hZonePen = NULL; } if (m_hSelZonePen) { DeleteObject(m_hSelZonePen); m_hSelZonePen = NULL; } if (m_hPalette) { DeleteObject(m_hPalette); m_hPalette = NULL; } CScrollView::OnDestroy(); } BOOL COCRFileView::OnEraseBkgnd(CDC* pDC) { CRect rcClient; GetClientRect(&rcClient); CBrush br(GetSysColor(DKGRAY_BRUSH)); FillOutsideRect(pDC, &br); return TRUE; } void COCRFileView::OnFileOpen() { OPENFILENAME OpenFileName; OPENDLGPARAMS FOParm; memset(&FOParm, 0, sizeof(OPENDLGPARAMS)); memset(&OpenFileName, 0, sizeof(OPENFILENAME)); FOParm.uStructSize = sizeof(OPENDLGPARAMS); FOParm.bPreviewEnabled = TRUE; FOParm.uDlgFlags = DLG_OPEN_SHOW_PROGRESSIVE | DLG_OPEN_SHOW_MULTIPAGE | DLG_OPEN_SHOW_LOADROTATED | DLG_OPEN_SHOW_LOADCOMPRESSED | DLG_OPEN_SHOW_FILEINFO | DLG_OPEN_SHOW_PREVIEW | DLG_OPEN_SHOW_DELPAGE | DLG_OPEN_SHOW_LOADOPTIONS | DLG_OPEN_SHOW_RASTEROPTIONS | DLG_OPEN_SHOW_PDFOPTIONS | DLG_OPEN_SHOW_VECTOROPTIONS | DLG_OPEN_VIEWTOTALPAGES | DLG_OPEN_ENABLESIZING | DLG_OPEN_NOFILEMUSTEXIST | DLG_OPEN_NOPATHMUSTEXIST | DLG_OPEN_USEFILESTAMP; OpenFileName.lStructSize = sizeof(OPENFILENAME); OpenFileName.hwndOwner = NULL; OpenFileName.lpstrFilter = NULL; OpenFileName.lpstrCustomFilter = NULL; OpenFileName.nMaxCustFilter = 0; OpenFileName.nFilterIndex = 0; OpenFileName.lpstrInitialDir = NULL; OpenFileName.lpstrTitle = TEXT("Open a File"); OpenFileName.nFileOffset = 0; OpenFileName.nFileExtension = 0; OpenFileName.lpstrDefExt = NULL; OpenFileName.Flags = 0; L_INT nRet = L_DlgOpen(m_hWnd, &OpenFileName, &FOParm); if (nRet == SUCCESS_DLG_OK) { FILEINFO FileInfo; memset(&FileInfo, 0, sizeof(FILEINFO)); L_INT nRet = L_FileInfo((L_TCHAR *)FOParm.pFileData[0].szFileName, &FileInfo, sizeof(FILEINFO), 0, NULL); if (nRet != SUCCESS) return; LOADFILEOPTION LoadOptions; if (m_LEADBitmap.Flags.Allocated) { L_FreeBitmap(&m_LEADBitmap); Reset(); } L_GetDefaultLoadFileOption(&LoadOptions, sizeof(LOADFILEOPTION)); LoadOptions.PageNumber = FOParm.pFileData[0].nPageNumber; nRet = L_LoadBitmap((L_TCHAR *)FOParm.pFileData[0].szFileName, &m_LEADBitmap, sizeof(BITMAPHANDLE), 0, ORDER_BGRORGRAY, &LoadOptions, NULL); if (nRet == SUCCESS) { UpdateScrollView(); m_bPageAdded = FALSE; } CleanOpenDlgParam(&FOParm); } } void COCRFileView::OnFileSave() { BeginWaitCursor(); SAVEDLGPARAMS FSParm; OPENFILENAME OpenFileName; L_TCHAR szFileName[_MAX_PATH]=TEXT(""); memset(&OpenFileName,0,sizeof(OPENFILENAME)); memset(&FSParm, 0, sizeof(SAVEDLGPARAMS)); OpenFileName.lStructSize = sizeof(OPENFILENAME); OpenFileName.lpstrInitialDir = NULL; OpenFileName.lpstrTitle = TEXT("Save a File"); OpenFileName.lpstrFile = szFileName; OpenFileName.nMaxFile = sizeof(szFileName)/sizeof(L_TCHAR); OpenFileName.lpstrFileTitle = FSParm.szFileName; OpenFileName.nMaxFileTitle = sizeof(FSParm.szFileName)/sizeof(L_TCHAR); OpenFileName.nFileOffset = 0; OpenFileName.Flags = 0; FSParm.uStructSize = sizeof(SAVEDLGPARAMS); FSParm.pBitmap = &m_LEADBitmap; FSParm.nQFactor = 2; FSParm.uDlgFlags = DLG_SAVE_AUTOPROCESS | DLG_SAVE_SHOW_FILEOPTIONS_MULTIPAGE | DLG_SAVE_SHOW_FILEOPTIONS_PROGRESSIVE | DLG_SAVE_SHOW_FILEOPTIONS_QFACTOR | DLG_SAVE_SHOW_FILEOPTIONS_STAMP | DLG_SAVE_SHOW_FILEOPTIONS_J2KOPTIONS | DLG_SAVE_SHOW_FILEOPTIONS_BASICJ2KOPTIONS; L_INT nRet = L_DlgSave(m_hWnd, &OpenFileName, &FSParm); if (!ISDLGSUCCESS(nRet)) { CString csBuffer; csBuffer.Format(TEXT("Can not save file,\nError code = %d\n"), nRet); AfxMessageBox(csBuffer); } EndWaitCursor(); } void COCRFileView::OnUpdateFileSave(CCmdUI* pCmdUI) { pCmdUI->Enable(m_LEADBitmap.Flags.Allocated); } void COCRFileView::OnOcrAddpage() { BeginWaitCursor(); if (!m_LEADBitmap.Flags.Allocated) return; L_INT nRet = L_DocAddPage(m_hDoc, &m_LEADBitmap, -1); if (nRet != SUCCESS) { CString csErr; csErr.Format(_T("Can't add page to engine\nError = %d\n"), nRet); AfxMessageBox(csErr); } else { L_DocExportPage(m_hDoc, &m_LEADBitmap, sizeof(BITMAPHANDLE), 0); L_DocSetActivePage(m_hDoc, 0); UpdateScrollView(); m_bPageAdded = TRUE; } EndWaitCursor(); } void COCRFileView::OnUpdateOcrAddpage(CCmdUI* pCmdUI) { pCmdUI->Enable(m_hDoc && m_LEADBitmap.Flags.Allocated && !m_bPageAdded); } void COCRFileView::OnOcrRecognize() { CString csMsg; csMsg.Format(TEXT("Do you want to delete all previous output files?")); int nAnswer = MessageBox(csMsg, TEXT("Delete output files"), MB_YESNO); if (nAnswer == IDYES) { CString csFile; csFile.Format(TEXT("%s\\ocrfile.rdf"), m_csImagesPath); DeleteFile(csFile); csFile.Format(TEXT("%s\\ocrfile_text_standard.txt"), m_csImagesPath); DeleteFile(csFile); csFile.Format(TEXT("%s\\ocrfile_text_smart.txt"), m_csImagesPath); DeleteFile(csFile); csFile.Format(TEXT("%s\\ocrfile_text_stripped.txt"), m_csImagesPath); DeleteFile(csFile); csFile.Format(TEXT("%s\\ocrfile_text_plain.txt"), m_csImagesPath); DeleteFile(csFile); csFile.Format(TEXT("%s\\ocrfile_text_comma_delimated.txt"), m_csImagesPath); DeleteFile(csFile); csFile.Format(TEXT("%s\\ocrfile_text_tab_delimited.txt"), m_csImagesPath); DeleteFile(csFile); csFile.Format(TEXT("%s\\ocrfile_ascii_formated.txt"), m_csImagesPath); DeleteFile(csFile); csFile.Format(TEXT("%s\\ocrfile_ascii_standard.txt"), m_csImagesPath); DeleteFile(csFile); csFile.Format(TEXT("%s\\ocrfile_ascii_standard_ex.txt"), m_csImagesPath); DeleteFile(csFile); csFile.Format(TEXT("%s\\ocrfile_general_word_processor.txt"), m_csImagesPath); DeleteFile(csFile); csFile.Format(TEXT("%s\\ocrfile_pdf.pdf"), m_csImagesPath); DeleteFile(csFile); csFile.Format(TEXT("%s\\ocrfile_pdf_image.pdf"), m_csImagesPath); DeleteFile(csFile); csFile.Format(TEXT("%s\\ocrfile_pdf_image_on_text.pdf"), m_csImagesPath); DeleteFile(csFile); csFile.Format(TEXT("%s\\ocrfile_pdf_image_only.pdf"), m_csImagesPath); DeleteFile(csFile); csFile.Format(TEXT("%s\\ocrfile_pdf_edited.pdf"), m_csImagesPath); DeleteFile(csFile); csFile.Format(TEXT("%s\\ocrfile_html_3_2.html"), m_csImagesPath); DeleteFile(csFile); csFile.Format(TEXT("%s\\ocrfile_html_4_0.html"), m_csImagesPath); DeleteFile(csFile); csFile.Format(TEXT("%s\\ocrfile_word.doc"), m_csImagesPath); DeleteFile(csFile); csFile.Format(TEXT("%s\\ocrfile_excel.xls"), m_csImagesPath); DeleteFile(csFile); csFile.Format(TEXT("%s\\ocrfile_wordperfect.wpt"), m_csImagesPath); DeleteFile(csFile); csFile.Format(TEXT("%s\\ocrfile_rtf.rtf"), m_csImagesPath); DeleteFile(csFile); csFile.Format(TEXT("%s\\ocrfile_rtf_ppt.rtf"), m_csImagesPath); DeleteFile(csFile); csFile.Format(TEXT("%s\\ocrfile_rtf_pub.rtf"), m_csImagesPath); DeleteFile(csFile); csFile.Format(TEXT("%s\\ocrfile_rtf_wordpad.rtf"), m_csImagesPath); DeleteFile(csFile); csFile.Format(TEXT("%s\\ocrfile_rtf_word_2000.rtf"), m_csImagesPath); DeleteFile(csFile); csFile.Format(TEXT("%s\\ocrfile_rtf_word_97.rtf"), m_csImagesPath); DeleteFile(csFile); csFile.Format(TEXT("%s\\ocrfile_rtf_word_95.rtf"), m_csImagesPath); DeleteFile(csFile); csFile.Format(TEXT("%s\\ocrfile_open_eBook.opf"), m_csImagesPath); DeleteFile(csFile); csFile.Format(TEXT("%s\\ocrfile_xml.xml"), m_csImagesPath); DeleteFile(csFile); csFile.Format(TEXT("%s\\ocrfile_2g2.txt"), m_csImagesPath); DeleteFile(csFile); csFile.Format(TEXT("%s\\ocrfile_2g3.txt"), m_csImagesPath); DeleteFile(csFile); } RECOGNIZEOPTS RecogOpts; CString csDataFile; csDataFile.Format(_T("%s\\ocrfile.rdf"), m_csImagesPath); memset(&RecogOpts, 0, sizeof(RECOGNIZEOPTS)); RecogOpts.uStructSize = sizeof(RECOGNIZEOPTS); RecogOpts.nPageIndexStart = 0; RecogOpts.nPagesCount = 1; RecogOpts.bEnableSubSystem = TRUE; RecogOpts.bEnableCorrection = TRUE; RecogOpts.SpellLangId = LANG_ID_ENGLISH; RecogOpts.pszFileName = (L_TCHAR *)(LPCTSTR)csDataFile; BeginWaitCursor(); m_bRecog = FALSE; L_INT nRet = L_DocRecognize(m_hDoc, &RecogOpts, NULL, this); EndWaitCursor(); if (nRet != SUCCESS) { AfxMessageBox(_T("Can't recognize the specific pages")); return; } else { CString csMsg; csMsg.Format(_T("The recognition process successful, you will find the result at (%s)"), csDataFile); AfxMessageBox(csMsg); } m_bRecog = TRUE; RedrawWindow(); } void COCRFileView::OnUpdateOcrRecognize(CCmdUI* pCmdUI) { pCmdUI->Enable(m_bPageAdded && !m_bRecog); } void COCRFileView::OnOcrSaveresultstoallfileformats() { CString csResultFile; RESULTOPTIONS resOpts; memset(&resOpts, 0, sizeof(RESULTOPTIONS)); BeginWaitCursor(); L_INT nRet = L_DocGetRecognitionResultOptions(m_hDoc, &resOpts, sizeof(RESULTOPTIONS)); if (nRet != SUCCESS) { AfxMessageBox(_T("Can't get the default recognition result options")); return; } resOpts.FormatLevel = FORMAT_LEVEL_FULL; resOpts.Format = DOC_TEXT_STANDARD; L_DocSetRecognitionResultOptions(m_hDoc, &resOpts); csResultFile.Format(_T("%s\\ocrfile_text_standard.txt"), m_csImagesPath); nRet = L_DocSaveResultsToFile(m_hDoc, (L_TCHAR *)(LPCTSTR)csResultFile); if (nRet != SUCCESS) AfxMessageBox(_T("Can't save recognition result to DOC_TEXT_STANDARD format")); resOpts.Format = DOC_TEXT_SMART; L_DocSetRecognitionResultOptions(m_hDoc, &resOpts); csResultFile.Format(_T("%s\\ocrfile_text_smart.txt"), m_csImagesPath); nRet = L_DocSaveResultsToFile(m_hDoc, (L_TCHAR *)(LPCTSTR)csResultFile); if (nRet != SUCCESS) AfxMessageBox(_T("Can't save recognition result to DOC_TEXT_SMART format")); resOpts.Format = DOC_TEXT_STRIPPED; L_DocSetRecognitionResultOptions(m_hDoc, &resOpts); csResultFile.Format(_T("%s\\ocrfile_text_stripped.txt"), m_csImagesPath); nRet = L_DocSaveResultsToFile(m_hDoc, (L_TCHAR *)(LPCTSTR)csResultFile); if (nRet != SUCCESS) AfxMessageBox(_T("Can't save recognition result to DOC_TEXT_STRIPPED format")); resOpts.Format = DOC_TEXT_PLAIN; L_DocSetRecognitionResultOptions(m_hDoc, &resOpts); csResultFile.Format(_T("%s\\ocrfile_text_plain.txt"), m_csImagesPath); nRet = L_DocSaveResultsToFile(m_hDoc, (L_TCHAR *)(LPCTSTR)csResultFile); if (nRet != SUCCESS) AfxMessageBox(_T("Can't save recognition result to DOC_TEXT_PLAIN format")); resOpts.Format = DOC_TEXT_COMMA_DELIMITED; L_DocSetRecognitionResultOptions(m_hDoc, &resOpts); csResultFile.Format(_T("%s\\ocrfile_text_comma_delimated.txt"), m_csImagesPath); nRet = L_DocSaveResultsToFile(m_hDoc, (L_TCHAR *)(LPCTSTR)csResultFile); if (nRet != SUCCESS) AfxMessageBox(_T("Can't save recognition result to DOC_TEXT_COMMA_DELIMITED format")); resOpts.Format = DOC_TEXT_TAB_DELIMITED; L_DocSetRecognitionResultOptions(m_hDoc, &resOpts); csResultFile.Format(_T("%s\\ocrfile_text_tab_delimited.txt"), m_csImagesPath); nRet = L_DocSaveResultsToFile(m_hDoc, (L_TCHAR *)(LPCTSTR)csResultFile); if (nRet != SUCCESS) AfxMessageBox(_T("Can't save recognition result to DOC_TEXT_TAB_DELIMITED format")); resOpts.Format = DOC_REC_ASCII_FORMATTED; L_DocSetRecognitionResultOptions(m_hDoc, &resOpts); csResultFile.Format(_T("%s\\ocrfile_ascii_formated.txt"), m_csImagesPath); nRet = L_DocSaveResultsToFile(m_hDoc, (L_TCHAR *)(LPCTSTR)csResultFile); if (nRet != SUCCESS) AfxMessageBox(_T("Can't save recognition result to DOC_REC_ASCII_FORMATTED format")); resOpts.Format = DOC_REC_ASCII_STANDARD; L_DocSetRecognitionResultOptions(m_hDoc, &resOpts); csResultFile.Format(_T("%s\\ocrfile_ascii_standard.txt"), m_csImagesPath); nRet = L_DocSaveResultsToFile(m_hDoc, (L_TCHAR *)(LPCTSTR)csResultFile); if (nRet != SUCCESS) AfxMessageBox(_T("Can't save recognition result to DOC_REC_ASCII_STANDARD format")); resOpts.Format = DOC_REC_ASCII_STANDARDEX; L_DocSetRecognitionResultOptions(m_hDoc, &resOpts); csResultFile.Format(_T("%s\\ocrfile_ascii_standard_ex.txt"), m_csImagesPath); nRet = L_DocSaveResultsToFile(m_hDoc, (L_TCHAR *)(LPCTSTR)csResultFile); if (nRet != SUCCESS) AfxMessageBox(_T("Can't save recognition result to DOC_REC_ASCII_STANDARDEX format")); resOpts.Format = DOC_GENERAL_WORD_PROCESSOR; L_DocSetRecognitionResultOptions(m_hDoc, &resOpts); csResultFile.Format(_T("%s\\ocrfile_general_word_processor.txt"), m_csImagesPath); nRet = L_DocSaveResultsToFile(m_hDoc, (L_TCHAR *)(LPCTSTR)csResultFile); if (nRet != SUCCESS) AfxMessageBox(_T("Can't save recognition result to DOC_GENERAL_WORD_PROCESSOR format")); resOpts.Format = DOC_PDF; L_DocSetRecognitionResultOptions(m_hDoc, &resOpts); csResultFile.Format(_T("%s\\ocrfile_pdf.pdf"), m_csImagesPath); nRet = L_DocSaveResultsToFile(m_hDoc, (L_TCHAR *)(LPCTSTR)csResultFile); if (nRet != SUCCESS) AfxMessageBox(_T("Can't save recognition result to DOC_PDF format")); resOpts.Format = DOC_PDF_IMAGE_SUBSTITUTES; L_DocSetRecognitionResultOptions(m_hDoc, &resOpts); csResultFile.Format(_T("%s\\ocrfile_pdf_image.pdf"), m_csImagesPath); nRet = L_DocSaveResultsToFile(m_hDoc, (L_TCHAR *)(LPCTSTR)csResultFile); if (nRet != SUCCESS) AfxMessageBox(_T("Can't save recognition result to DOC_PDF_IMAGE_SUBSTITUTES format")); resOpts.Format = DOC_PDF_IMAGE_ON_TEXT; L_DocSetRecognitionResultOptions(m_hDoc, &resOpts); csResultFile.Format(_T("%s\\ocrfile_pdf_image_on_text.pdf"), m_csImagesPath); nRet = L_DocSaveResultsToFile(m_hDoc, (L_TCHAR *)(LPCTSTR)csResultFile); if (nRet != SUCCESS) AfxMessageBox(_T("Can't save recognition result to DOC_PDF_IMAGE_ON_TEXT format")); resOpts.Format = DOC_PDF_IMAGEONLY; L_DocSetRecognitionResultOptions(m_hDoc, &resOpts); csResultFile.Format(_T("%s\\ocrfile_pdf_image_only.pdf"), m_csImagesPath); nRet = L_DocSaveResultsToFile(m_hDoc, (L_TCHAR *)(LPCTSTR)csResultFile); if (nRet != SUCCESS) AfxMessageBox(_T("Can't save recognition result to DOC_PDF_IMAGEONLY format")); resOpts.Format = DOC_PDF_EDITED; L_DocSetRecognitionResultOptions(m_hDoc, &resOpts); csResultFile.Format(_T("%s\\ocrfile_pdf_edited.pdf"), m_csImagesPath); nRet = L_DocSaveResultsToFile(m_hDoc, (L_TCHAR *)(LPCTSTR)csResultFile); if (nRet != SUCCESS) AfxMessageBox(_T("Can't save recognition result to DOC_PDF_EDITED format")); resOpts.Format = DOC_HTML_3_2; L_DocSetRecognitionResultOptions(m_hDoc, &resOpts); csResultFile.Format(_T("%s\\ocrfile_html_3_2.html"), m_csImagesPath); nRet = L_DocSaveResultsToFile(m_hDoc, (L_TCHAR *)(LPCTSTR)csResultFile); if (nRet != SUCCESS) AfxMessageBox(_T("Can't save recognition result to DOC_HTML_3_2 format")); resOpts.Format = DOC_HTML_4_0; L_DocSetRecognitionResultOptions(m_hDoc, &resOpts); csResultFile.Format(_T("%s\\ocrfile_html_4_0.html"), m_csImagesPath); nRet = L_DocSaveResultsToFile(m_hDoc, (L_TCHAR *)(LPCTSTR)csResultFile); if (nRet != SUCCESS) AfxMessageBox(_T("Can't save recognition result to DOC_HTML_4_0 format")); resOpts.Format = DOC_WORD_97_2000_XP; L_DocSetRecognitionResultOptions(m_hDoc, &resOpts); csResultFile.Format(_T("%s\\ocrfile_word.doc"), m_csImagesPath); nRet = L_DocSaveResultsToFile(m_hDoc, (L_TCHAR *)(LPCTSTR)csResultFile); if (nRet != SUCCESS) AfxMessageBox(_T("Can't save recognition result to DOC_WORD_97_2000_XP format")); resOpts.Format = DOC_EXCEL_97_2000; L_DocSetRecognitionResultOptions(m_hDoc, &resOpts); csResultFile.Format(_T("%s\\ocrfile_excel.xls"), m_csImagesPath); nRet = L_DocSaveResultsToFile(m_hDoc, (L_TCHAR *)(LPCTSTR)csResultFile); if (nRet != SUCCESS) AfxMessageBox(_T("Can't save recognition result to DOC_EXCEL_97_2000 format")); resOpts.Format = DOC_WORDPERFECT_8; L_DocSetRecognitionResultOptions(m_hDoc, &resOpts); csResultFile.Format(_T("%s\\ocrfile_wordperfect.wpt"), m_csImagesPath); nRet = L_DocSaveResultsToFile(m_hDoc, (L_TCHAR *)(LPCTSTR)csResultFile); if (nRet != SUCCESS) AfxMessageBox(_T("Can't save recognition result to DOC_WORDPERFECT_8 format")); resOpts.Format = DOC_RTF; L_DocSetRecognitionResultOptions(m_hDoc, &resOpts); csResultFile.Format(_T("%s\\ocrfile_rtf.rtf"), m_csImagesPath); nRet = L_DocSaveResultsToFile(m_hDoc, (L_TCHAR *)(LPCTSTR)csResultFile); if (nRet != SUCCESS) AfxMessageBox(_T("Can't save recognition result to DOC_RTF format")); resOpts.Format = DOC_PPT_97_RTF; L_DocSetRecognitionResultOptions(m_hDoc, &resOpts); csResultFile.Format(_T("%s\\ocrfile_rtf_ppt.rtf"), m_csImagesPath); nRet = L_DocSaveResultsToFile(m_hDoc, (L_TCHAR *)(LPCTSTR)csResultFile); if (nRet != SUCCESS) AfxMessageBox(_T("Can't save recognition result to DOC_PPT_97_RTF format")); resOpts.Format = DOC_PUB_98_RTF; L_DocSetRecognitionResultOptions(m_hDoc, &resOpts); csResultFile.Format(_T("%s\\ocrfile_rtf_pub.rtf"), m_csImagesPath); nRet = L_DocSaveResultsToFile(m_hDoc, (L_TCHAR *)(LPCTSTR)csResultFile); if (nRet != SUCCESS) AfxMessageBox(_T("Can't save recognition result to DOC_PUB_98_RTF format")); resOpts.Format = DOC_WORDPAD_RTF; L_DocSetRecognitionResultOptions(m_hDoc, &resOpts); csResultFile.Format(_T("%s\\ocrfile_rtf_wordpad.rtf"), m_csImagesPath); nRet = L_DocSaveResultsToFile(m_hDoc, (L_TCHAR *)(LPCTSTR)csResultFile); if (nRet != SUCCESS) AfxMessageBox(_T("Can't save recognition result to DOC_WORDPAD_RTF format")); resOpts.Format = DOC_RTF_WORD_2000; L_DocSetRecognitionResultOptions(m_hDoc, &resOpts); csResultFile.Format(_T("%s\\ocrfile_rtf_word_2000.rtf"), m_csImagesPath); nRet = L_DocSaveResultsToFile(m_hDoc, (L_TCHAR *)(LPCTSTR)csResultFile); if (nRet != SUCCESS) AfxMessageBox(_T("Can't save recognition result to DOC_RTF_WORD_2000 format")); resOpts.Format = DOC_RTF_WORD_97; L_DocSetRecognitionResultOptions(m_hDoc, &resOpts); csResultFile.Format(_T("%s\\ocrfile_rtf_word_97.rtf"), m_csImagesPath); nRet = L_DocSaveResultsToFile(m_hDoc, (L_TCHAR *)(LPCTSTR)csResultFile); if (nRet != SUCCESS) AfxMessageBox(_T("Can't save recognition result to DOC_RTF_WORD_97 format")); resOpts.Format = DOC_RTF_WORD_6_95; L_DocSetRecognitionResultOptions(m_hDoc, &resOpts); csResultFile.Format(_T("%s\\ocrfile_rtf_word_95.rtf"), m_csImagesPath); nRet = L_DocSaveResultsToFile(m_hDoc, (L_TCHAR *)(LPCTSTR)csResultFile); if (nRet != SUCCESS) AfxMessageBox(_T("Can't save recognition result to DOC_RTF_WORD_6_95 format")); resOpts.Format = DOC_OPEN_EBOOK_1_0; L_DocSetRecognitionResultOptions(m_hDoc, &resOpts); csResultFile.Format(_T("%s\\ocrfile_open_eBook.opf"), m_csImagesPath); nRet = L_DocSaveResultsToFile(m_hDoc, (L_TCHAR *)(LPCTSTR)csResultFile); if (nRet != SUCCESS) AfxMessageBox(_T("Can't save recognition result to DOC_OPEN_EBOOK_1_0 format")); resOpts.Format = DOC_XML; L_DocSetRecognitionResultOptions(m_hDoc, &resOpts); csResultFile.Format(_T("%s\\ocrfile_xml.xml"), m_csImagesPath); nRet = L_DocSaveResultsToFile(m_hDoc, (L_TCHAR *)(LPCTSTR)csResultFile); if (nRet != SUCCESS) AfxMessageBox(_T("Can't save recognition result to DOC_XML format")); resOpts.Format = DOC_2G_TYPE_2; L_DocSetRecognitionResultOptions(m_hDoc, &resOpts); csResultFile.Format(_T("%s\\ocrfile_2g2.txt"), m_csImagesPath); nRet = L_DocSaveResultsToFile(m_hDoc, (L_TCHAR *)(LPCTSTR)csResultFile); if (nRet != SUCCESS) AfxMessageBox(_T("Can't save recognition result to DOC_2G_TYPE_2 format")); resOpts.Format = DOC_2G_TYPE_3; L_DocSetRecognitionResultOptions(m_hDoc, &resOpts); csResultFile.Format(_T("%s\\ocrfile_2g3.txt"), m_csImagesPath); nRet = L_DocSaveResultsToFile(m_hDoc, (L_TCHAR *)(LPCTSTR)csResultFile); if (nRet != SUCCESS) AfxMessageBox(_T("Can't save recognition result to DOC_2G_TYPE_3 format")); AfxMessageBox(_T("Save recognition result to all supported file formats is finished")); EndWaitCursor(); } void COCRFileView::OnUpdateOcrSaveresultstoallfileformats(CCmdUI* pCmdUI) { pCmdUI->Enable(m_bRecog); } void COCRFileView::Reset() { L_InitBitmap(&m_LEADBitmap, sizeof(BITMAPHANDLE), 0, 0, 0); if (m_bPageAdded) L_DocRemovePage(m_hDoc, 0); m_bPageAdded = FALSE; m_bRecog = FALSE; m_hZonePen = NULL; m_hSelZonePen = NULL; m_hPalette = NULL; }