home *** CD-ROM | disk | FTP | other *** search
- VERSION 4.00
- Begin VB.Form OCR
- Caption = "Form1"
- ClientHeight = 1380
- ClientLeft = 1500
- ClientTop = 2880
- ClientWidth = 6690
- Height = 1785
- Left = 1440
- LinkTopic = "Form1"
- ScaleHeight = 1380
- ScaleWidth = 6690
- Top = 2535
- Width = 6810
- Attribute VB_Name = "OCR"
- Attribute VB_Creatable = False
- Attribute VB_Exposed = False
- Option Explicit
- Private Sub Form_Load()
- Dim imagefn As String
- Dim textfn As String
- Dim page As String
- Dim data As String
-
- Dim retval As Long
- Dim imgtype As Long
- Dim imgdepth As Long
- Dim junk As Long
- Dim count As Long
- Dim i As Long
- Dim apobj As Object
- On Error GoTo optixerr
- Set apobj = GetObject("", "Optix.Application")
- imagefn = apobj.GetActiveFilename
- If imagefn <> "" Then
- ' Make sure this is an image that TextBridge can read
-
- retval = apobj.GetActiveInfo(junk, junk, junk, junk, imgtype, junk, imgdepth)
- If (imgtype <> TYPE_PIXD) And _
- (((imgtype <> TYPE_TIFF) And (imgtype <> TYPE_BMP)) Or (imgdepth <> 1)) Then
- MsgBox "Can only OCR black and white TIF or BMP files."
- GoTo optixend
- End If
-
- ' Create a filename for the text
-
- textfn = imagefn + ".RTF"
- On Error Resume Next
- Kill textfn
-
- ' Do the OCR
-
- If (imgtype = TYPE_PIXD) Then
-
- ' Open each page
-
- count = apobj.GetCollItemCount
- For i = 1 To count
-
- page = apobj.GetCollItemInfo(i, imgtype, junk, junk)
- If (imgtype = TYPE_TIFF) Or (imgtype = TYPE_BMP) Then
-
- ' Open the image page
-
- apobj.OpenCollItem i, False
- retval = apobj.GetActiveInfo(junk, junk, junk, junk, imgtype, junk, imgdepth)
- If ((imgtype = TYPE_TIFF) Or (imgtype = TYPE_BMP)) And (imgdepth = 1) Then
-
- ' Process the page
-
- imagefn = apobj.GetActiveFilename
- page = imagefn + "X"
- On Error Resume Next
- Kill page
-
- retval = TextBridgeOcr(imagefn, page)
- If retval <> 0 Then
- apobj.CloseActiveWindow
- GoTo optixend
- End If
-
- ' Append text file
-
- Open page For Input Access Read As #1
- Open textfn For Binary Access Write As #2
- data = Input$(LOF(1), 1)
- Put #2, LOF(2) + 1, data
- Close
- On Error Resume Next
- Kill page
- End If
-
- apobj.CloseActiveWindow
-
- End If
-
- Next i ' end for each page
-
- Else
-
- ' Process the image
-
- retval = TextBridgeOcr(imagefn, textfn)
-
- End If
-
- ' Open the text file in Optix
-
- If retval = 0 Then
- apobj.OpenFile (textfn)
- Else
- If retval = timeouterr Then
- MsgBox "Timeout waiting for TextBridge."
- Else
- If retval = ocrerr Then
- MsgBox "Error starting TextBridge"
- Else
- If retval = registryerr Then
- MsgBox "Could not get the registry key for TextBridge"
- End If
- End If
- End If
- End If
- Else
- MsgBox "The Optix file has not yet been saved."
- End If
-
- optixend:
- Set apobj = Nothing
- End
- optixerr:
- MsgBox "Cannot get Optix.Application object."
- End
-
- End Sub
-