Working with Pages (C++ Builder 6.0)
Take the following steps to create and run a program that shows how to work with pages in an OCR document. Remember, the purpose of the tutorials is to provide you with a quick and easy way to generate an OCR program.
1. |
Start C++ Builder 6.0. |
2. |
If you didn’t import LEAD Raster Object before, import it as follows: |
|
On the Project pull-down menu, use the Import Type library… and select the LEAD Raster object library (14.5). Press install, and then compile and install the package dclusr.dpk. |
3 |
If you didn’t import LEAD Raster Process Object before, import it as follows: |
|
On the Project pull-down menu, use the Import Type library… and select the LEAD Raster Process object library (14.5). Press install, and then compile and install the package dclusr.dpk. |
4. |
If you didn’t import LEAD Raster OCR Document Object before, import it as follows: |
|
On the Project pull-down menu, use the Import Type library… and select the LEAD Raster OCR Document object library (14.5). Press install, and then compile and install the package dclusr.dpk. |
5. |
If you didn’t import LEAD Raster IO Object before, import it as follows: |
|
On the Project pull-down menu, use the Import Type library… and select the LEAD Raster IO object library (14.5). Press install, and then compile and install the package dclusr.dpk. |
6. |
From the ActiveX tab, Select and Add LEADRasterIO, LEADRasterProcess, and OCR LEADRasterDocument controls to your form. |
7. |
Include the following files in the "Unit1.h" file. |
#include "LTRASTERLib_TLB.h"
8. |
Add the following declaration to the public section of "Unit1.h": |
ILEADRaster * pLEADRasterObj;
9. |
Add 6 buttons to your form and name them as follows: |
|
|
Name |
Caption |
|
btnStartUp |
Start Up |
|
btnShutDown |
Shut Down |
|
btnAddPage |
Add Page |
|
btnRemovePage |
Remove Page |
|
btnSetLanguages |
Set Languages |
|
btnFlipPage |
Flip Page |
10. |
Code the main form's Create procedure as follows. In online help, you can use the Edit pull-down menu to copy the block of code. |
void __fastcall TForm1::FormCreate(TObject *Sender)
{
CoCreateInstance ( CLSID_LEADRaster,
NULL,
CLSCTX_ALL,
IID_ILEADRaster,
(void**)&pLEADRasterObj );
if ( pLEADRasterObj == NULL )
{
ShowMessage ( "Error Creating LEAD Raster Object" );
Application->Terminate ( );
}
}
11. |
Code the main form's Close procedure as follows. In online help, you can use the Edit pull-down menu to copy the block of code. |
void __fastcall TForm1::FormClose(TObject *Sender, TCloseAction &Action)
{
if ( pLEADRasterObj )
{
pLEADRasterObj->Release ( );
pLEADRasterObj= NULL;
}
}
12. |
Code the btnStartUp button's click procedure as follows: |
void __fastcall TForm1::btnStartUpClick(TObject *Sender)
{
//notice the OCR key is a test key.
pLEADRasterObj->UnlockSupport ( L_SUPPORT_OCR, AnsiToOLESTR("TestKey") );
LEADRasterDocument1->StartUp ( );
}
13. |
Code the btnShutDown button's click procedure as follows: |
void __fastcall TForm1::btnShutDownClick(TObject *Sender)
{
LEADRasterDocument1->ShutDown( );
}
14. |
Code the btnAddPage button's click procedure as follows: |
void __fastcall TForm1::btnAddPageClick(TObject *Sender)
{
int nRet;
int nPageNumber= 0;
nRet= LEADRasterIO1->Load ( pLEADRasterObj, AnsiToOLESTR("c:\\OCRTEST.gif"), 0, 0, 1 );
if ( nRet != 0 )
ShowMessage ( "Error loading file" );
nRet= LEADRasterDocument1->AddPage ( pLEADRasterObj, nPageNumber );
if ( nRet == 0 )
{
ShowMessage ( "Page Width = " + IntToStr(LEADRasterDocument1->PageWidth [nPageNumber]) + "\n" +
"Page Height = " + IntToStr(LEADRasterDocument1->PageHeight [nPageNumber]) + "\n" +
"Page Bits Per Pixel = " + IntToStr(LEADRasterDocument1->PageBitsPerPixel [nPageNumber]));
}
else
ShowMessage ( "The engine could not add a new page to the Document" );
}
15. |
Code the btnRemovePage button's click procedure as follows: |
void __fastcall TForm1::btnRemovePageClick(TObject *Sender)
{
int i;
int nRet;
int nPageCount;
nPageCount= LEADRasterDocument1->PageCount;
for ( i= 0; i < nPageCount; i ++ )
{
LEADRasterDocument1->CleanupPages(True);
nRet= LEADRasterDocument1->RemovePage (i);
if ( nRet == 0 )
ShowMessage ( "The page # " + IntToStr(i) + "is removed successfully" );
}
}
16. |
Code the btnSetLanguages button's click procedure as follows: |
void __fastcall TForm1::btnSetLanguagesClick(TObject *Sender)
{
int nRet;
LEADRasterDocument1->set_ActiveLanguagesCount ( 1 );
LEADRasterDocument1->set_ActiveLanguage ( 0, LANGID_ENGLISH );
nRet= LEADRasterDocument1->SelectLanguages ();
if ( nRet != 0 )
ShowMessage ( "Error " + IntToStr(nRet) + "Setting English as default language" );
else
ShowMessage ( "English is Set as the active language" );
}
17. |
Code the btnFlipPage button's click procedure as follows: |
void __fastcall TForm1::btnFlipPageClick(TObject *Sender)
{
int nRet;
LEADRasterDocument1->ExportPage ( pLEADRasterObj, 0 );
LEADRasterProcess1->Flip ( pLEADRasterObj );
nRet= LEADRasterDocument1->UpdatePage ( pLEADRasterObj, 0 );
if ( nRet == 0 )
ShowMessage ( "The specified page is updated successfuly" );
else
ShowMessage ( "Error " + IntToStr(nRet) + " in updating page bitmap for page # 0" );
LEADRasterDocument1->set_ActivePageIndex ( 0 );
}
18. |
Run your program to test it. |
19. |
Save the project to use as a starting point for other tasks in this tutorial. |