Using the SimpleOCR ActiveX Control (VB)

You are here:
< All Topics

This is an example of how to perform on a multi-page image file using X and VB.

Sub DoOCR (filename as String) 
Basic function to perform  on a multi-page TIFF image file.
Dim objOCR as  ' object 
Dim ret, img, imgSet, i as Long 'Function return value, single image pointer, multiple image pointer, page counter 
Dim strOCRResult as String 'String variable to hold OCR result 

Set objOCR = New SimpleOCR 

ret = objOCR.OCRSetOutputHandlerX(AddressOf myOutputHandler) 
if isnull(ret) then
'Error occurred
end if 

imgSet = objOCR.LoadMultipleImgX(filename) 
if isnull(imgSet) then
'Error occurred
end if 

objOCR.SetLanguageX(ENGLISH,".") 'Set language to English 
objOCR.SetOutputModeX(OM_TEXT) 'Set output mode to Text 

For i = 1 to objOCR.GetNBImagesX(imgSet)
img = objOCR.GetImage(imgSet,i) 'Get the current page 
ret = objOCR.OCRX(img,0) 'Perform OCR on page 
if ret > 0 then 
'Error occurred 
end if

MsgBox strOCRResult 

objOCR.FreeMultipleImgX img
End Sub 

Sub myoutputhandler(ByVal infotype As Integer, ByVal param As Integer) 
'This simple output handler sets the strOCRResult string to the OCR result.
'Return Value 

'infotype - Contant indicating type of information contained in param. 
'param - data from . See SetOCROutputHandler declaration for details. 

'Output handler must be declared in BAS modules and not form code 
'since the AddressOf method requires it for passing as a pointer 

On Error Resume Next 'required to avoid propagating DLL errors to VB 

Select Case infotype
strOCRResult = strOCRResult + CStr(Chr(param)) 
strOCRResult = strOCRResult + "\\n"
End Select
End Sub
Previous SimpleOCR:SDK Functions AddImage
Table of Contents
Contact Us for FREE Consultation on Your OCR Project
Go to Top