Working with Pages (ASP - VBScript)

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=VBScript%>
<%
   Dim LEADRaster
   Dim LEADRasterIO
   Dim LEADRasterProc
   Dim LEADRasterDoc
   Dim ZonData

   Set LEADRaster = Server.CreateObject("LEADRaster.LEADRaster.145")
   Set LEADRasterIO = Server.CreateObject("LEADRasterIO.LEADRasterIO.145")
   Set LEADRasterProc = Server.CreateObject("LEADRasterProcess.LEADRasterProcess.145")
   Set LEADRasterDoc = Server.CreateObject("LEADRasterDocument.LEADRasterDocument.145")
   Set ZoneData = Server.CreateObject("LTZoneData.LTZoneData.145")

   Sub SetActiveLangs()
      Dim nRet
      Dim LANGID_ENGLISH

      LANGID_ENGLISH = 0
      LEADRasterDoc.ActiveLanguagesCount = 1
      LEADRasterDoc.ActiveLanguage(0) = LANGID_ENGLISH
      nRet = LEADRasterDoc.SelectLanguages()
      If (nRet <> 0) Then
         Response.Write "Error " + CStr(nRet) + "Setting English as default language"+ "<BR>"
      Else
         Response.Write "English is Set as the active language" + "<BR>"
      End If
   End Sub

   Sub AddPage()
      Dim L_SUPPORT_OCR
      L_SUPPORT_OCR = 3

      LEADRaster.UnlockSupport L_SUPPORT_OCR, "OCR Key Goes Here"
      LEADRasterDoc.StartUp

      Dim nPageNumber
      Dim nRet

      nRet = LEADRasterIO.Load(LEADRaster, "D:\Ocr\LETTER.TIF", 0, 0, 1)
      If (nRet <> 0) Then
         Response.Write "Error loading file" + "<BR>"
      End If

      nRet = LEADRasterDoc.AddPage(LEADRaster, nPageNumber)
      If (nRet = 0) Then
         Response.Write "Page Width = " + CStr(LEADRasterDoc.PageWidth(nPageNumber)) + Chr(13) + "Page Height = " + CStr(LEADRasterDoc.PageHeight(nPageNumber)) + Chr(13) + "Page Bits Per Pixel = " + CStr(CStr(LEADRasterDoc.PageBitsPerPixel(nPageNumber))) + "<BR>"
      Else
         Response.Write "The engine could not add a new page to the Document" + "<BR>"
      End If                  

      SetActiveLangs
   End Sub      

   Sub RemovePage()
      Dim nRet
      Dim nPageCount
      Dim I

      nPageCount = LEADRasterDoc.PageCount
      For i = 0 To  nPageCount - 1
         LEADRasterDoc.CleanupPages(True)
         nRet = LEADRasterDoc.RemovePage(i)
         If (nRet = 0) Then
            Response.Write "The page # " + CStr(i) + "is removed successfully" + "<BR>"
         End If
      Next
   End Sub

   Sub FlipPage()
      Dim nRet

      nRet = LEADRasterDoc.ExportPage(LEADRaster, 0)
      LEADRasterProc.Flip LEADRaster
      nRet = LEADRasterDoc.UpdatePage(LEADRaster, 0)
      If (nRet = 0) Then
         Response.Write "The specified page is updated successfuly" + "<BR>"
      Else
         Response.Write "Error " + CStr(nRet) + " in updating page bitmap for page # 0" + "<BR>"
         LEADRasterDoc.ActivePageIndex = 0
      End If
   End Sub

   AddPage
   FlipPage
   RemovePage
%>