[jawsscripts] Re: OCRSnapObject Failing!

  • From: "Martin Slack" <m.g.slack@xxxxxxxxxxxx>
  • To: <jawsscripts@xxxxxxxxxxxxx>
  • Date: Sun, 31 Jan 2010 16:06:40 -0000

Yes, Visual Studio Express seems to be based on the dot Net framework.  You 
need to download the required flavour (C#, C++, Visual Basic )

  Martin


----- Original Message ----- 
From: "Donald Marang" <donald.marang@xxxxxxxxx>
To: <jawsscripts@xxxxxxxxxxxxx>
Sent: Sunday, January 31, 2010 2:54 PM
Subject: [jawsscripts] Re: OCRSnapObject Failing!


> Thanks!  I will give it a try as I play around with Visual Studio Express.
> Is Express sucificent to write .Net applications?  I may want to write a
> DLNA (Digital Living Network Alliance) application in the near future.
>
> Don Marang
>
> --------------------------------------------------
> From: "Martin Slack" <m.g.slack@xxxxxxxxxxxx>
> Sent: Sunday, January 31, 2010 4:48 AM
> To: <jawsscripts@xxxxxxxxxxxxx>
> Subject: [jawsscripts] Re: OCRSnapObject Failing!
>
>> Hi Don,
>>
>>  Here is a VBScript version of your example which works on my system,
>> using
>> MS Office Pro 2003 on XP, even with Office 2003 SP3 installed.
>>
>>  I've left a number of VBScript dialogs in place which you should be able
>> to remove with no problem.
>>
>>  Martin...
>>
>> Option Explicit
>>
>> Const forWriting = 2
>> Const forAppending = 8
>>
>> Dim inputFile, outputFile
>> Dim strRecText
>> Dim Doc1 ' MODI.Document
>> Dim imageCounter
>> Dim fso, path, Count
>>
>> inputFile = "biscuits.tif"
>> strRecText = ""
>>
>> ' Assuming .tif file is in same folder as .vbs file
>> Set fso = CreateObject("Scripting.FileSystemObject")
>> Set inputFile = fso.GetFile("biscuits.tif")
>> path = inputFile.ShortPath
>>
>> WScript.Echo path
>>
>> Set Doc1 = CreateObject ("MODI.Document")
>> Doc1.Create(path)
>> 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
>>
>> WScript.Echo "number of images: " & Doc1.Images.Count
>>
>> For Each imageCounter In Doc1.Images
>>    strRecText = strRecText & imageCounter.Layout.Text
>> Next
>>
>> WScript.Echo strRecText
>>
>> ' this will write, not append
>> Set outputFile= fso.CreateTextFile("c:\testfile.txt", forWriting)
>> outputFile.Write (strRecText)
>> outputFile.Close
>>
>> WScript.Echo "Text saved to " &  "c:\testfile.txt"
>>
>> ' Clean up
>> Doc1.Close()
>> Set outputFile = Nothing
>> Set Doc1 = Nothing
>> Set inputFile = Nothing
>> Set fso = Nothing
>>
>>
>> ----- Original Message ----- 
>> From: "Donald Marang" <donald.marang@xxxxxxxxx>
>> To: <jawsscripts@xxxxxxxxxxxxx>
>> Sent: Saturday, January 30, 2010 11:45 PM
>> Subject: [jawsscripts] OCRSnapObject Failing!
>>
>>
>>>I think I have the basic structure and JAWS Script statements I thought
>>>should work.  Unfortunately it returns nothing!  How do you know if the
>>>CreateObject function returns the expected object?  I attempt to retrieve
>>>the number of images (pages), I would expect a value of one, but nothing
>>>is
>>>returned.  Could someone familiar with objects in JAWS look to see if I
>>>made a dumb mistake?
>>> I included a copy of a Visual Basic routine to OCR an image file and
>>> writes the plain text to a file.  I simplified this as I converted it to
>>> JAWS script code.  I would think a screenshot image would only be one
>>> page.
>>>
>>> Following the example is my script.  Some of the necessary lines are
>>> commented out until I ensure the active code is working.  I also
>>> attempted
>>> to use my constant, MODI_DLL_PATH, directly in the CreateObject
>>> statements.  Both with single '\' and double '\\' characters.  Doing so
>>> caused all three statements to fail.
>>>
>>> --- Start of example
>>> Example from Wikipedia and MSDN for "MODI OCR" in Visual Basic .NET
>>> </wiki/Visual_Basic_.NET> follows:
>>> You can program the MODI object model from any development tool that
>>> supports
>>> the Component Object Model (COM) by setting a reference to the Microsoft
>>> Office
>>> Document Imaging 11.0 (Office 2003) (or 12.0, which is Office 2007,  I
>>> saw
>>> somewhere else) Type Library.
>>>
>>> Dim inputFile As String = "C:\test\multipage.tif"
>>> Dim strRecText As String = ""
>>> Dim Doc1 As MODI.Document
>>>
>>> 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 As Integer = 0 To (Doc1.Images.Count - 1) ' work your
>>> way
>>> through each page of results
>>>    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() ' clean up
>>> Doc1 = Nothing
>>> --- End of example
>>> Include "hjconst.jsh"
>>>
>>> Const
>>> CRLF = "\13\10", ; Cariage return followed by line feed character
>>> SCREEN_CAPTURE_FILE = "ScreenCapture.tif", ; Temp file placed in the 
>>> JAWS
>>> user settings directory
>>> NIRCMD = "nircmd.exe", ; Command Line Utility from:
>>> http://www.nirsoft.net/utils/nircmd.html
>>> IMAGE_OCR = "MSPVIEW.EXE -o ",
>>> IMAGE_READ = "MSPVIEW.EXE -r ",
>>> ; Microsoft Office Document Imaging Viewer Control 11.0 or 12.0
>>> (MDIVWCTL.DLL)
>>> MODI_DLL_PATH = "\"C:\\Program Files\\Common Files\\Microsoft
>>> Shared\\MOD\\MDIVWCTL.DLL\""
>>>
>>> Script OCRSnapshotObject ()
>>> Var
>>> String sImageFile,
>>> String sCmdUtility,
>>> String sExecute,
>>> Object oNull,
>>> Object oDoc,
>>> Object oAllImages,
>>> Object oImage,
>>> Object oLayout,
>>> Int iCount,
>>> Int iChars,
>>> Int iWords,
>>> String sText
>>>
>>> ; Close virtual buffer if open
>>> If UserBufferIsActive () Then
>>> UserBufferDeactivate ()
>>> EndIf
>>> ; Set temporary image filename
>>> Let sImageFile = GetJAWSSettingsDirectory () + "\\" + 
>>> SCREEN_CAPTURE_FILE
>>> Let sImageFile = "\"" + sImageFile  + "\"" ; Enclose in quotes in case
>>> there is a space in the path
>>> ; Set Command Line Utility path
>>> Let sCmdUtility = GetJAWSSettingsDirectory () + "\\" + NIRCMD
>>> Let sCmdUtility = "\"" + sCmdUtility + "\"" ; Enclose in quotes in case
>>> there is a space in the path
>>> ; Capture image of foreground active window
>>> Let sExecute = sCmdUtility + " savescreenshotwin " + sImageFile
>>> ; SayString ("Will perform save screenshot to file = \"" + sExecute +
>>> "\"")
>>> Run (sExecute)
>>> SayMessage (OT_MESSAGE, "Screen image has been captured.  Please wait 
>>> for
>>> OCR conversion.")
>>> Delay (10) ; make sure the file is not in use
>>>
>>> ; Run Microsoft Office Document Imageing Object Model to perform OCR
>>> ; Not sure how to create / open / register ovject as performed by
>>> Visual.Net Basic in the nnext two lines
>>> ; Dim Doc1 As MODI.Document
>>> ; Let oDoc = New MODI.Document
>>>
>>> ; Method used in Homer Jax
>>> Let oDoc = CreateObjectEx ("MODI.Document", False)
>>> If ! oDoc Then
>>> SayMessage (OT_ERROR, "Could not create object using first call!")
>>> Let oDoc = CreateObject ("MODI.Document")
>>> EndIf
>>> If ! oDoc Then
>>> SayMessage (OT_ERROR, "Could not create objectusing second call!")
>>> ; Running out of possibilities, try the last variety
>>> Let oDoc = CreateObjectEx ("MODI.Document", True)
>>> EndIf
>>> If ! oDoc Then
>>> SayMessage (OT_ERROR, "Could not create objectusing third call!")
>>>    Return oNull
>>> EndIf
>>> SayString ("Document object created!")
>>> oDoc.Create(sImageFile) ; loads the image into the object
>>> ; SayString ("Image file =" + sImageFile)
>>> Let oAllImages = oDoc.Images
>>> Let iCount = oAllImages.Count
>>> SayString ("pages in file = " + IntToString (iCount))
>>> ; oDoc.OCR() ; this will ocr all pages of a multi-page tiff file
>>> ; oDoc.Save() ; this will save the deskewed reoriented images, and the
>>> OCR
>>> text, back to the inputFile
>>> ; Let oImage = oDoc.Images(0) ; first page of possible multi-page image
>>> SayString ("OCR complete!")
>>> ; Let oLayout = oImage.Layout ; OCR information
>>> ; Let sText = oLayout.Text ; this puts the ocr results into a string
>>> SayString ("text = \"" + sText + "\"")
>>> ; Let iChars = oLayout.NumChars
>>> ; Let iWords = oLayout.NumWords
>>> SayMessage (OT_MESSAGE, "Screen image has been converted to text.")
>>> SayMessage (OT_MESSAGE, "Converted " + IntToString (iChars) + "
>>> characters, and " + IntToString (iWords) + " words")
>>>
>>> ; View converted text
>>> SayMessage (OT_USER_BUFFER  , sText + CRLF + "Press Escape to close this
>>> message.")
>>> oDoc.Close() ; Clean up
>>> Let oLayout = oNull
>>> Let oImage =oNull
>>> Let oAllImages = oNull
>>> Let oDoc =oNull
>>> EndScript
>>>
>>> Don Marang
>>> __________
>>> Visit and contribute to The JAWS Script Repository 
>>> http://jawsscripts.com
>>>
>>> View the list's information and change your settings at
>>> //www.freelists.org/list/jawsscripts
>>>
>>
>> __________
>> Visit and contribute to The JAWS Script Repository http://jawsscripts.com
>>
>> View the list's information and change your settings at
>> //www.freelists.org/list/jawsscripts
>>
> __________
> Visit and contribute to The JAWS Script Repository http://jawsscripts.com
>
> View the list's information and change your settings at
> //www.freelists.org/list/jawsscripts
> 

__________ 
Visit and contribute to The JAWS Script Repository http://jawsscripts.com

View the list's information and change your settings at 
//www.freelists.org/list/jawsscripts

Other related posts: