read the data from tiff file using MODI and OCR in VBA

divya_agarwal

Board Regular
Joined
Nov 24, 2008
Messages
51
Hi,
Can any body correct me to read the data from tiff image by using MODI and OCR .
Plz check the code.
Dim doc1 As MODI.Document
Dim inputFile As String
Dim strRecText As String
Dim imageCounter As Integer

inputFile = Application.GetOpenFilename
'(Title:="Please choose a file to import", _
'FileFilter:="Image Files *.tif (*.tif)")
strRecText = ""
Set doc1 = New MODI.Document
doc1.Create (inputFile)
doc1.OCR ' this will ocr all pages of a multi-page tiff file
doc1.Save ' this will save the deskewed reoriented images, and the OCR text, back to the inputFile
For imageCounter = 0 To (doc1.Images.Count - 1) ' work your way through each page of results
strRecText = strRecText & doc1.Images(imageCounter).Layout.Text ' this puts the ocr results into a string
Next

File.AppendAllText("C:\test\testmodi.txt", strRecText) ' write the OCR file out to disk
doc1.Close
doc1 = Nothing



that program is showing error in the colored line.

Regards,
Divya Agarwal


 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
Why not use a more traditional method to write to a text file?

Replace your failing line with the following 4 lines.

Code:
fnum = FreeFile()
Open "C:\test\testmodi.txt" For Output As fnum
Print #fnum, strRecText
Close #fnum
 
Upvote 0
This is the complete code I used.

Code:
Sub OCRReader()
Dim doc1 As MODI.Document
Dim inputFile As String
Dim strRecText As String
Dim imageCounter As Integer
inputFile = Application.GetOpenFilename
strRecText = ""
Set doc1 = New MODI.Document
doc1.Create (inputFile)
doc1.OCR ' this will ocr all pages of a multi-page tiff file
For imageCounter = 0 To (doc1.Images.Count - 1) ' work your way through each page of results
    strRecText = strRecText & doc1.Images(imageCounter).Layout.Text ' this puts the ocr results into a string
Next
fnum = FreeFile()
Open "C:\Test\testmodi.txt" For Output As fnum
    Print #fnum, strRecText
Close #fnum
doc1.Close
End Sub
 
Upvote 0
Oh almost forgot, make sure you add "Microsoft Office Document Imaging 11.0 Type Library" in as a reference :)
 
Upvote 0
ihave Microsoft Office Document Imaging 12.0 Lobrary

and while i do select this and run the progm it display error

"name conflicts with existing module,project or library"
 
Upvote 0
Thank u so much
i got my error i delect previous one 1.0 type library and select 12.0 type.
It is working.

Cooooooooool

Thanks a lot
 
Upvote 0

Forum statistics

Threads
1,214,400
Messages
6,119,284
Members
448,885
Latest member
LokiSonic

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top