Working with Recognition Results (JavaScript)
Take the following steps to add code to the existing project that will let you save the recognition results:
1. |
Start with the program you created in Recognizing Pages. |
2. |
Add the following code between the <BODY> and </BODY> tags to add three buttons to the page: |
<INPUT TYPE="button" VALUE="Get Output Format" LANGUAGE="JavaScript"
OnClick="GetOutputFormat()" ID="Button9" NAME="Button8">
<INPUT TYPE="button" VALUE="Save Document" LANGUAGE="JavaScript"
OnClick="SaveDocument()" ID="Button10" NAME="Button8">
3. |
Add the following code between the <SCRIPT> and </SCRIPT> tags: |
function GetOutputFormat()
{
var nRet;
nRet = LEADRasterDoc.GetOutputFileFormats();
if (nRet != 0)
alert("Error" + nRet + "in enumerating available file formats");
}
function SaveDocument()
{
var nRet;
var FORMATLEVEL_FULL = 0;
var SELPREDEFINED = 2;
var PAPER_A4 = 0;
nRet = LEADRasterDoc.GetRecognitionResultOptions();
alert("Format Name = " + LEADRasterDoc.FileFormatInfo.FormatName + "\n" +
"Format DLL Name = " + LEADRasterDoc.FileFormatInfo.DLLName + "\n" +
"Format Ext Name = " + LEADRasterDoc.FileFormatInfo.ExtName);
if (nRet == 0)
{
LEADRasterDoc.ResultOptions.FormatLevel = FORMATLEVEL_FULL;
LEADRasterDoc.ResultOptions.DocumentOptions.PaperSizeMode = SELPREDEFINED;
LEADRasterDoc.ResultOptions.DocumentOptions.PaperType = PAPER_A4;
}
LEADRasterDoc.SetRecognitionResultOptions();
nRet = LEADRasterDoc.SaveDocument("c:\\test.doc");
if (nRet != 0)
alert("Error" + nRet + "in saving recognition result to a file");
}
4. |
Add the following code between the <HEAD> and </HEAD> tags to handle the EnumOutputFileFormats event: |
<SCRIPT LANGUAGE="JavaScript" FOR="LEADRasterDoc" EVENT="EnumOutputFileFormats(Format)">
<!--
var nRet;
var OUTTYPE_PLAIN = 0;
var OUTTYPE_WORD_PROCESSOR = 1;
var OUTTYPE_TRUE_WORD_PROCESSOR = 2;
var OUTTYPE_TABLE = 3;
var OUTTYPE_UNKNOWN = 4;
nRet = LEADRasterDoc.GetFileFormatInfo(Format);
if (nRet == 0)
{
alert("Format Name = " + LEADRasterDoc.FileFormatInfo.FormatName + "\n" +
"Format DLL Name = " + LEADRasterDoc.FileFormatInfo.DLLName + "\n" +
"Format Ext Name = " + LEADRasterDoc.FileFormatInfo.ExtName);
switch (LEADRasterDoc.FileFormatInfo.Type)
{
case OUTTYPE_PLAIN:
alert("Format Type = Plain");
break;
case OUTTYPE_WORD_PROCESSOR:
alert("Format Type = Word Processor");
break;
case OUTTYPE_TRUE_WORD_PROCESSOR:
alert("Format Type = True Word Processor");
break;
case OUTTYPE_TABLE:
alert("Format Type = Table");
break;
case OUTTYPE_UNKNOWN:
alert("Format Type = Unknown");
break;
}
}
//-->
</SCRIPT>
5. |
Run your page to test it. |