Working with Pages

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 Visual Basic.

2.

Add the LEAD Raster Object Library and LEAD Raster Variant Object Library to your project.

 

On the Project pull-down menu, use the References option, and select the LEAD Raster Object Library (14.5).

 

On the Project pull-down menu, use the References option, and select the LEAD Raster Variant Object Library (14.5).

3.

Add the LEAD Raster Process Object Library to your project.

 

On the Project pull-down menu, use the References option, and select the LEAD Raster Process Object Library (14.5).

4.

Add the LEAD Raster OCR Document Object Library to your project.

 

On the Project pull-down menu, use the References option, and select the LEAD Raster OCR Document Object Library (14.5).

5.

Add the LEAD Raster IO Object Library to your project.

 

On the Project pull-down menu, use the References option, and select the LEAD Raster IO Object Library (14.5).

6.

Add a command button to your form and name it as follows:

 

Name

Caption

 

STARTUP

Start Up

 

ADDPAGE

Add Page

 

SETLANGUAGES

Set Langs

 

SHUTDOWN

Shut Down

 

REMOVEPAGE

Remove Page

 

FLIPPAGE

Flip Page

7.

Add the following code to the general declarations section of your project:

Dim WithEvents LEADRasterDoc As LEADRasterDocument
Dim LeadRaster As New LeadRaster
Dim LeadRasterIO as New LEADRasterIO

8.

Add the following initialization code to the main form's Load procedure. In Online help, you can use the Edit pull-down menu to copy the block of code.

Private Sub Form_Load()
   Set LEADRasterDoc = New LEADRasterDocument
End Sub

9.

Code the STARTUP button's click procedure as follows:

Private Sub STARTUP _Click()
   ' notice the OCR key is a test key.
   LeadRaster.UnlockSupport L_SUPPORT_OCR, "TestKey"
   LEADRasterDoc.StartUp
End Sub

10.

Code the SHUTDOWN button's click procedure as follows:

Private Sub SHUTDOWN_Click()
   LEADRasterDoc.ShutDown
End Sub

11.

Code the ADDPAGE button's click procedure as follows:

Private Sub ADDPAGE_Click()
   Dim nPageNumber As Long
   Dim nRet As Long

   nRet = LeadRasterIO.Load(LeadRaster, "c:\OCRTEST.gif", 0, 0, 1)
   If (nRet <> 0) Then
      MsgBox "Error loading file"
   End If

   nRet = LEADRasterDoc.ADDPAGE(LeadRaster, nPageNumber)
   If (nRet = 0) Then
      MsgBox "Page Width = " + Str(LEADRasterDoc.PageWidth (nPageNumber)) + Chr$(13) + _
      "Page Height = " + Str(LEADRasterDoc.PageHeight (nPageNumber)) + Chr$(13) + _
      "Page Bits Per Pixel = " + Str(Str(LEADRasterDoc.PageBitsPerPixel (nPageNumber)))
   Else
      MsgBox "The engine could not add a new page to the Document"
   End If
End sub

12.

Code the SETLANGUAGES button's click procedure as follows:

Private Sub SETLANGUAGES_Click()
   Dim nRet As Long
   LEADRasterDoc.ActiveLanguagesCount = 1
   LEADRasterDoc.ActiveLanguage (0) = LANGID_ENGLISH
   nRet = LEADRasterDoc.SelectLanguages ()
   If (nRet <> 0) Then
      MsgBox "Error " + Str(nRet) + "Setting English as default language"

   Else
      MsgBox "English is Set as the active language"
End If

End Sub

13.

Code the REMOVEPAGE button's click procedure as follows:

Private Sub REMOVEPAGE_Click()
   Dim nRet As Long
   Dim nPageCount As Long
   Dim i As Long

   nPageCount = LEADRasterDoc.PageCount
   For i = 0 To  nPageCount - 1
      RasterDoc.CleanupPages True
      nRet = LEADRasterDoc.RemovePage(i) 
      If (nRet = 0) Then
         MsgBox "The page # " + Str(i) + "is removed successfully"
      End If
   Next i
End Sub

14.

Code the FLIPPAGE button's click procedure as follows:

Private Sub FLIPPAGE_Click()
   Dim nRet As Long
   Dim LEADRasterProc As New LEADRasterProcess
   nRet = LEADRasterDoc.ExportPage (LeadRaster, 0)
   LEADRasterProc.Flip LeadRaster
   nRet = LEADRasterDoc.UpdatePage (LeadRaster, 0)
   If (nRet = 0) Then
      MsgBox "The specified page is updated successfuly"
   Else
      MsgBox "Error " + Str(nRet) + " in updating page bitmap for page # 0"
      LEADRasterDoc.ActivePageIndex = 0
   End If
End Sub

15.

Run your program to test it.

16.

Save this project to use for testing other code samples.