Working with Pages (JavaScript)

Copy and paste the following code into an HTML 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:

<HTML>
   <HEAD>
      <SCRIPT LANGUAGE="JavaScript">
      <!--      
      function Window_OnUnload()
      {
         LEADRasterDoc.ShutDown();
      }

      function SetActiveLangs()
      {
         var nRet;
         var LANGID_ENGLISH = 0;

         LEADRasterDoc.ActiveLanguagesCount = 1;
         LEADRasterDoc.ActiveLanguage(0) = LANGID_ENGLISH;
         nRet = LEADRasterDoc.SelectLanguages();
         if (nRet != 0)
            alert("Error " + nRet + "Setting English as default language");
         else
            alert("English is Set as the active language");         
      }

      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)
            alert("Error loading file");         

         nRet = LEADRasterDoc.AddPage(LEADRaster, nPageNumber);
         if (nRet == 0)
            alert("Page Width = " + LEADRasterDoc.PageWidth(nPageNumber) + "\n" + "Page Height = " + LEADRasterDoc.PageHeight(nPageNumber) + "\n" + "Page Bits Per Pixel = " + LEADRasterDoc.PageBitsPerPixel(nPageNumber));
         else
            alert("The engine could not add a new page to the Document");         

         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)
               alert("The page # " + i + "is removed successfully");            
         }
      }

      function FlipPage()
      {
         var nRet;

         nRet = LEADRasterDoc.ExportPage(LEADRaster, 0);
         LEADRasterProc.Flip(LEADRaster);
         nRet = LEADRasterDoc.UpdatePage(LEADRaster, 0);
         if (nRet == 0)
            alert("The specified page is updated successfuly")
         else
         {
            alert("Error " + nRet + " in updating page bitmap for page # 0");
            LEADRasterDoc.ActivePageIndex = 0;
         }
      }      
      //-->
      </SCRIPT>

      <TITLE>LEADTOOLS JavaScript COM OCR Example</TITLE>
   </HEAD>
   <BODY onunload="Window_OnUnload()">
      <OBJECT CLASSID="clsid:5220cb21-c88d-11cf-b347-00aa00a28331" ALIGN="baseline" BORDER="0" WIDTH="1"
HEIGHT="1" ID="Object1">
          <PARAM NAME="LPKPath" VALUE="path to LPK file/LTOCX14n.Lpk">
      </OBJECT><BR>

      <object classid="clsid:00140700-B1BA-11CE-ABC6-F5B2E79D9E3F" ID="LEADRaster">
      </object>

      <OBJECT ID="RasterIO" NAME="LEADRasterIO" CLASSID="CLSID:0014070E-B1BA-11CE-ABC6-F5B2E79D9E3F"
CODEBASE="path to CAB file/Ltrio14n.cab">
          <P>This is not supported in the web browser.</P>
      </OBJECT><BR>

      <object classid="clsid:00140B30-B1BA-11CE-ABC6-F5B2E79D9E3F" ID="LEADRasterDoc">
      </object>

<OBJECT ID="LEADRasterProc" NAME="LEADRasterProc" CLASSID="CLSID:00140712-B1BA-11CE-ABC6
F5B2E79D9E3F" CODEBASE="path to CAB file/Ltrpr14n.cab">
         <P>This is not supported in the web browser.</P>
      </OBJECT><BR>

      <object classid="clsid:00140B4A-B1BA-11CE-ABC6-F5B2E79D9E3F" ID="ZoneData">
      </object>

      <FORM NAME="LEADForm" ID="Form1">
         <INPUT TYPE="button" VALUE="Add Page" LANGUAGE="JavaScript" OnClick="AddPage()" ID="Button1"
NAME="Button1">
         <INPUT TYPE="button" VALUE="Remove Page" LANGUAGE="JavaScript" OnClick="RemovePage()" ID="Button2"
NAME="Button2">
         <INPUT TYPE="button" VALUE="Flip Page" LANGUAGE="JavaScript" OnClick="FlipPage()" ID="Button3"
NAME="Button3">
      </FORM>
   </BODY>
</HTML>