home *** CD-ROM | disk | FTP | other *** search
/ PC Open 15 / PCOPEN15.ISO / Optix / DATA1.CAB / Script_Source / OCR.frm (.txt) next >
Encoding:
Visual Basic Form  |  1997-11-26  |  4.3 KB  |  136 lines

  1. VERSION 4.00
  2. Begin VB.Form OCR 
  3.    Caption         =   "Form1"
  4.    ClientHeight    =   1380
  5.    ClientLeft      =   1500
  6.    ClientTop       =   2880
  7.    ClientWidth     =   6690
  8.    Height          =   1785
  9.    Left            =   1440
  10.    LinkTopic       =   "Form1"
  11.    ScaleHeight     =   1380
  12.    ScaleWidth      =   6690
  13.    Top             =   2535
  14.    Width           =   6810
  15. Attribute VB_Name = "OCR"
  16. Attribute VB_Creatable = False
  17. Attribute VB_Exposed = False
  18. Option Explicit
  19. Private Sub Form_Load()
  20.     Dim imagefn As String
  21.     Dim textfn As String
  22.     Dim page As String
  23.     Dim data As String
  24.         
  25.     Dim retval As Long
  26.     Dim imgtype As Long
  27.     Dim imgdepth As Long
  28.     Dim junk As Long
  29.     Dim count As Long
  30.     Dim i As Long
  31.     Dim apobj As Object
  32.     On Error GoTo optixerr
  33.     Set apobj = GetObject("", "Optix.Application")
  34.     imagefn = apobj.GetActiveFilename
  35.     If imagefn <> "" Then
  36.         ' Make sure this is an image that TextBridge can read
  37.         
  38.         retval = apobj.GetActiveInfo(junk, junk, junk, junk, imgtype, junk, imgdepth)
  39.         If (imgtype <> TYPE_PIXD) And _
  40.            (((imgtype <> TYPE_TIFF) And (imgtype <> TYPE_BMP)) Or (imgdepth <> 1)) Then
  41.             MsgBox "Can only OCR black and white TIF or BMP files."
  42.             GoTo optixend
  43.         End If
  44.         
  45.         ' Create a filename for the text
  46.         
  47.         textfn = imagefn + ".RTF"
  48.         On Error Resume Next
  49.         Kill textfn
  50.         
  51.         ' Do the OCR
  52.         
  53.         If (imgtype = TYPE_PIXD) Then
  54.         
  55.             ' Open each page
  56.             
  57.             count = apobj.GetCollItemCount
  58.             For i = 1 To count
  59.             
  60.                 page = apobj.GetCollItemInfo(i, imgtype, junk, junk)
  61.                 If (imgtype = TYPE_TIFF) Or (imgtype = TYPE_BMP) Then
  62.                 
  63.                     ' Open the image page
  64.                     
  65.                     apobj.OpenCollItem i, False
  66.                     retval = apobj.GetActiveInfo(junk, junk, junk, junk, imgtype, junk, imgdepth)
  67.                     If ((imgtype = TYPE_TIFF) Or (imgtype = TYPE_BMP)) And (imgdepth = 1) Then
  68.                     
  69.                         ' Process the page
  70.                         
  71.                         imagefn = apobj.GetActiveFilename
  72.                         page = imagefn + "X"
  73.                         On Error Resume Next
  74.                         Kill page
  75.                         
  76.                         retval = TextBridgeOcr(imagefn, page)
  77.                         If retval <> 0 Then
  78.                             apobj.CloseActiveWindow
  79.                             GoTo optixend
  80.                         End If
  81.                         
  82.                         ' Append text file
  83.                         
  84.                         Open page For Input Access Read As #1
  85.                         Open textfn For Binary Access Write As #2
  86.                         data = Input$(LOF(1), 1)
  87.                         Put #2, LOF(2) + 1, data
  88.                         Close
  89.                         On Error Resume Next
  90.                         Kill page
  91.                     End If
  92.                     
  93.                     apobj.CloseActiveWindow
  94.                     
  95.                 End If
  96.                 
  97.             Next i  ' end for each page
  98.             
  99.         Else
  100.         
  101.             ' Process the image
  102.             
  103.             retval = TextBridgeOcr(imagefn, textfn)
  104.             
  105.         End If
  106.                 
  107.         ' Open the text file in Optix
  108.         
  109.         If retval = 0 Then
  110.             apobj.OpenFile (textfn)
  111.         Else
  112.             If retval = timeouterr Then
  113.                 MsgBox "Timeout waiting for TextBridge."
  114.             Else
  115.                 If retval = ocrerr Then
  116.                     MsgBox "Error starting TextBridge"
  117.                 Else
  118.                     If retval = registryerr Then
  119.                         MsgBox "Could not get the registry key for TextBridge"
  120.                     End If
  121.                 End If
  122.             End If
  123.         End If
  124.     Else
  125.         MsgBox "The Optix file has not yet been saved."
  126.     End If
  127.         
  128. optixend:
  129.     Set apobj = Nothing
  130.     End
  131. optixerr:
  132.     MsgBox "Cannot get Optix.Application object."
  133.     End
  134.             
  135. End Sub
  136.