The information on this topic is deprecated as of LEADTOOLS v16.5.
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.Start Visual Basic 6 and create new project 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.
Add the RasterCodecs to your project.
On the Project pull-down menu, use the References option, and select the LTDCodecsInterop.
Add the RasterDocumentEngine to your project.
On the Project pull-down menu, use the References option, and select the LTDDocumentInterop.
Add the RasterSupport to your project.
On the Project pull-down menu, use the References option, and select the LTDInterop.
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
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
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
Drag and drop five command buttons in Form1. Leave all the buttons names as the default "Command1, Command2 ..." Change the following properties of Command1: Property Value Caption StartUp Change the following properties of Command2: Property Value Caption Add Page Change the following properties of Command3: Property Value Caption Remove Pages Change the following properties of Command4: Property Value Caption Find Zones Change the following properties of Command5: Property Value Caption Shutdown
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
Add the following code for the Command2 control’s click procedure: Private Sub Command2_Click() Set RasterImageViewer1.Image = codecs.Load_12("C:\Users\Public\Documents\LEADTOOLS 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
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
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
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
Build, and Run the program to test it. Save this project to use for testing other code samples.