Example Macro to Convert a TIFF file to Text
This post will be short because I spent the weekend on developing some artwork (and one failed) and it is now getting late. I do want to post a macro that I found in Stack Overview (I thought I copied the link) and fixed to work on my PC, altering it a little to fix my situation. Before this macro can work, you need to go into Tools - Reference and find the reference Microsoft Office Document Imaging 12. To get that you need to install SharePoint designer 2007 - but only parts of it.
The site to get the download and associated instructions: https://support.microsoft.com/en-us/kb/982760
Okay, here's the macro:
Sub TestOCR()
' lifted from http://en.wikipedia.org/wiki/Microsoft_Office_Document_Imaging
Dim inputFile As String
Dim strRecText As String
Dim Doc1 As MODI.Document
Dim imageCounter As Integer
Dim DocCount As Integer 'number of pages in scanned/ocr document
inputFile = "U:SCANSScan3.pdf"
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
Doc1.OCR
Doc1.Save
DocCount = Doc1.Images.Count - 1
For imageCounter = 0 To DocCount
strRecText = strRecText & Doc1.Images(imageCounter).Layout.Text
Next
'File.AppendAllText("C:testtestmodi.txt", strRecText) ' write the OCR file out to disk
'File.AppendAllText ("U:SCANStestmodi.txt", strRecText)
Dim fso As Object
Set fso = CreateObject("Scripting.FileSystemObject")
Dim oFile As Object
Set oFile = fso.CreateTextFile("U:SCANStestmodi.txt")
oFile.WriteLine strRecText
oFile.Close
Set fso = Nothing
Set oFile = Nothing
Doc1.Close
Doc1 = Nothing
End Sub
You must be logged in to post a comment.