Recognizing Pages (Visual Basic Script)

Take the following steps to add code to the existing page that will let you recognize pages:

1.

Start with the program you created in Working with Pages.

2.

Add the following code between the <BODY> and </BODY> tags to add three buttons to the page:

<INPUT TYPE="button" VALUE="Recognize" LANGUAGE="VBScript"
         OnClick="Recognize" ID="Button7" NAME="Button7">

<INPUT TYPE="button" VALUE="Get Status" LANGUAGE="VBScript"
         OnClick="GetStatus" ID="Button8" NAME="Button8">

3.

Add the following code between the <SCRIPT> and </SCRIPT> tags:

Sub Recognize()
         Dim nRet
         Dim LANGID_ENGLISH

         LANGID_ENGLISH = 0        
         LEADRasterDoc.SpellLanguageID = LANGID_ENGLISH
         LEADRasterDoc.EnableSubSystem = True
         LEADRasterDoc.EnableCorrection = True

         LEADRasterDoc.RecognitionDataFileName = "D:\Ocr\LETTER.TIF"

         nRet = LEADRasterDoc.Recognize(0, 1)
         If (nRet = 0) Then
            MsgBox "The engine finished recognizing the specified pages successfully"
         Else
            MsgBox "Error" + CStr(nRet) + "in recognized specified pages"
         End If
End Sub      

Sub GetStatus()
         Dim nRet
         nRet = LEADRasterDoc.GetStatus()
         If (nRet = 0) Then
            MsgBox "Recognition Time = " + CStr(LEADRasterDoc.RecognizeStatus.RecognizedTime) + Chr(13) + _
                  "Total Recognized Characters = " + CStr(LEADRasterDoc.RecognizeStatus.RecognizedCharacterCount) + Chr(13) + _
                  "Total Recognized Words = " + CStr(LEADRasterDoc.RecognizeStatus.RecognizedWordCount) + Chr(13) + _
                  "Total Rejected Characters = " + CStr(LEADRasterDoc.RecognizeStatus.RejectCharacterCount) + Chr(13) + _
                  "Total Rejected Words = " + CStr(LEADRasterDoc.RecognizeStatus.RejectWordCount)
         End If
End Sub

4.

Add the following code between the <HEAD> and </HEAD> tags to handle the RecognitionStatus event:

<SCRIPT LANGUAGE="VBScript" FOR="LEADRasterDoc" EVENT="RecognitionStatus(iRecogPage, iError)">
      <!--
         MsgBox "The page # " + CStr(iRecogPage) + "is finished its recognition" + Chr(13) + _
               "The recognition return code = " + CStr(iError)
         'continue to recognize next page
         LEADRasterDoc.EnableStopRecognizeStatus = False
      //-->
</SCRIPT>

5.

Run your page to test it.

6.

Save this page to use for testing other code samples.