Working with Pages (ASP - JavaScript)
Copy and paste the following code into an ASP file 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.
<%@ Language=JavaScript %>
<%
var LEADRaster = Server.CreateObject("LEADRaster.LEADRaster.145");
var LEADRasterIO = Server.CreateObject("LEADRasterIO.LEADRasterIO.145");
var LEADRasterProc = Server.CreateObject("LEADRasterProcess.LEADRasterProcess.145");
var LEADRasterDoc = Server.CreateObject("LEADRasterDocument.LEADRasterDocument.145");
var ZoneData = Server.CreateObject("LTZoneData.LTZoneData.145");
function SetActiveLangs()
{
var nRet;
var LANGID_ENGLISH = 0;
LEADRasterDoc.ActiveLanguagesCount = 1;
LEADRasterDoc.ActiveLanguage(0) = LANGID_ENGLISH;
nRet = LEADRasterDoc.SelectLanguages();
if (nRet != 0)
Response.Write("Error " + nRet + "Setting English as default language" + "<BR>");
else
Response.Write("English is Set as the active language" + "<BR>");
}
function AddPage()
{
var L_SUPPORT_OCR = 3;
LEADRaster.UnlockSupport(L_SUPPORT_OCR, "OCR Key Goes Here");
LEADRasterDoc.StartUp();
var nPageNumber;
var nRet;
nRet = LEADRasterIO.Load(LEADRaster, "D:\\Ocr\\LETTER.TIF", 0, 0, 1);
if (nRet != 0)
Response.Write("Error loading file" + "<BR>");
nRet = LEADRasterDoc.AddPage(LEADRaster, nPageNumber);
if (nRet == 0)
Response.Write("Page Width = " + LEADRasterDoc.PageWidth(nPageNumber) + "<BR>" + "Page Height = " + LEADRasterDoc.PageHeight(nPageNumber) + "<BR>" + "Page Bits Per Pixel = " + LEADRasterDoc.PageBitsPerPixel(nPageNumber) + "<BR>");
else
Response.Write("The engine could not add a new page to the Document" + "<BR>");
SetActiveLangs();
}
function RemovePage()
{
var nRet;
var nPageCount;
var i;
nPageCount = LEADRasterDoc.PageCount;
for (i = 0; i < nPageCount; i++)
{
LEADRasterDoc.CleanupPages(true);
nRet = LEADRasterDoc.RemovePage(i);
if (nRet = 0)
Response.Write("The page # " + i + "is removed successfully" + "<BR>");
else
Response.Write("The page # " + i + "is not removed successfully" + "<BR>");
}
}
function FlipPage()
{
var nRet;
nRet = LEADRasterDoc.ExportPage(LEADRaster, 0);
LEADRasterProc.Flip(LEADRaster);
nRet = LEADRasterDoc.UpdatePage(LEADRaster, 0);
if (nRet == 0)
Response.Write("The specified page is updated successfuly" + "<BR>");
else
{
Response.Write("Error " + nRet + " in updating page bitmap for page # 0" + "<BR>");
LEADRasterDoc.ActivePageIndex = 0;
}
}
AddPage();
FlipPage();
RemovePage();
%>