Send comments on this topic. | Back to Introduction - All Topics | Help Version 15.12.21
COM Interoperability: 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 6 and create new project
  2. Add the LEAD RasterImageViewer Control to your project.

    On the Project pull-down menu, use the Components option, and select the LTDWinFormsInterop..

    Select the RasterImageViewer control; then add the control to your main form. Size and position the control as you want it to appear at run time.

  3. Add the RasterCodecs to your project.

    On the Project pull-down menu, use the References option, and select the LTDCodecsInterop.

  4. Add the RasterDocumentEngine to your project.

    On the Project pull-down menu, use the References option, and select the LTDDocumentInterop.

  5. Add the RasterSupport to your project.

    On the Project pull-down menu, use the References option, and select the LTDInterop.

  6. Add the following private variables to the Form1, select View menu, then select Code:
    
    Dim documentEngine As RasterDocumentEngine
    Dim codecs As RasterCodecs
    Dim bOcrStarted As Boolean
    
  7. Add an event handler to the Form1 Load event and add the following code:
    
    Private Sub Form_Load()
       Set documentEngine = New RasterDocumentEngine
       Set codecs = New RasterCodecs
    
       codecs.Startup
       bOcrStarted = False
    End Sub
    
  8. Add an event handler to the Form1 Unload event and add the following code:
    
    Private Sub Form_Unload(Cancel As Integer)
       codecs.Shutdown
       If bOcrStarted Then
          documentEngine.Shutdown
       End If
    End Sub
    
  9. Drag and drop five command buttons in Form1. Leave all the buttons names as the default "Command1, Command2 ..."
    1. Change the following properties of Command1:
      PropertyValue
      CaptionStartUp
    2. Change the following properties of Command2:
      PropertyValue
      CaptionAdd Page
    3. Change the following properties of Command3:
      PropertyValue
      CaptionRemove Pages
    4. Change the following properties of Command4:
      PropertyValue
      CaptionFind Zones
    5. Change the following properties of Command5:
      PropertyValue
      CaptionShutdown
  10. Add the following code for the Command1 control’s click procedure:
    
    Private Sub Command1_Click()
      Dim support As New RasterSupport
      ' Unlock Support for Ocr
      ' Note that this is a sample key, which will not work in your toolkit
      support.Unlock RasterSupportType_Ocr, "TestKey"
      
      ' Start up the Ocr engine
      documentEngine.Startup
      MsgBox ("Ocr Object has been started successfully")
      bOcrStarted = True
    End Sub
    
  11. Add the following code for the Command2 control’s click procedure:
     
    Private Sub Command2_Click()
      Set RasterImageViewer1.Image = codecs.Load_12("C:\Program Files\LEAD Technologies\LEADTOOLS 15\Images\ocr1.tif")
      
      'Some information about the new added image
      Dim msg As String
      msg = "Page Width = " + CStr(RasterImageViewer1.Image.Width) + Chr(13) + _
            "Page Height = " + CStr(RasterImageViewer1.Image.Height) + Chr(13) + _
            "Page Bits Per Pixel = " + CStr(RasterImageViewer1.Image.BitsPerPixel)
      MsgBox msg
      
      'Add the image as a page to the RasterDocumentEngine object
      documentEngine.AddPage RasterImageViewer1.Image, -1
    End Sub
    
  12. Add the following code for the Command3 control’s click procedure:
    
    Private Sub Command3_Click()
      ' Get the number of pages of the RasterDocument object
      Dim pageCount As Integer
      Dim i As Integer
      pageCount = documentEngine.pageCount
      
      ' Loop over all the RasterDocument object pages to remove them
      For i = 0 To pageCount - 1
         documentEngine.RemovePage 0
      Next i
      
      Set RasterImageViewer1.Image = Nothing
      MsgBox "All the pages have been removed"
    End Sub
    
  13. Add the following code for the Command4 control’s click procedure:
    
    Private Sub Command4_Click()
       documentEngine.EnableZoneForceSingleColumn = True
       documentEngine.ShowZoneGridlines = True
       documentEngine.FindZones 0, Nothing
    
       MsgBox "Automatic zones method finds all available zones into the specified pages successfully"
    End Sub
    
  14. Add the following code for the Command5 control’s click procedure:
    
    Private Sub Command5_Click()
       ' Shut down the RasterDocument engine
       documentEngine.Shutdown
       MsgBox "Ocr object has been shut down"
       bOcrStarted = False
    End Sub
    
  15. Build, and Run the program to test it.
  16. Save this project to use for testing other code samples.