Recognizing Pages (JavaScript)
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="JavaScript"
OnClick="Recognize()" ID="Button7" NAME="Button7">
<INPUT TYPE="button" VALUE="Get Status" LANGUAGE="JavaScript"
OnClick="GetStatus()" ID="Button8" NAME="Button8">
3. |
Add the following code between the <SCRIPT> and </SCRIPT> tags: |
function Recognize()
{
var nRet;
var 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)
alert("The engine finished recognizing the specified pages successfully");
else
alert("Error" + nRet + "in recognized specified pages");
}
function GetStatus()
{
var nRet;
LEADRasterDoc.EnableFireRecognizeStatus = true;
nRet = LEADRasterDoc.GetStatus();
if (nRet == 0)
alert("Recognition Time = " + LEADRasterDoc.RecognizeStatus.RecognizedTime + "\n" +
"Total Recognized Characters = " + LEADRasterDoc.RecognizeStatus.RecognizedCharacterCount + "\n" +
"Total Recognized Words = " + LEADRasterDoc.RecognizeStatus.RecognizedWordCount + "\n" +
"Total Rejected Characters = " + LEADRasterDoc.RecognizeStatus.RejectCharacterCount + "\n" +
"Total Rejected Words = " + LEADRasterDoc.RecognizeStatus.RejectWordCount);
}
4. |
Add the following code between the <HEAD> and </HEAD> tags to handle the RecognitionStatus event: |
<SCRIPT LANGUAGE="JavaScript" FOR="LEADRasterDoc" EVENT="RecognitionStatus(iRecogPage, iError)">
<!--
alert("The page # " + iRecogPage + "is finished its recognition" + "\n" +
"The recognition return code = " + 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. |