News, links, downloads, tips and tricks on Microsoft Access and related

About Me Search
Name:Alex Dybenko

Location:Moscow, Russia

Wednesday, January 18, 2006

Document scan in MODI

I was recently asked to make some code in order to “scan documents into Access database”. First idea was to use Microsoft Office Document Imaging (MODI). But there is no method to start scan process! There is also no way to instantiate MODI Viewer with CreateObject(), so user can press scan button there. Ok, next I found a Microsoft Windows Image Acquisition Library (WMI), which is looks like what I need, but it is too low level for solution I need to build. Ok, I can build my own MSPSCAN.EXE, but this will takes me more number of hours my client expected.

Ilixis Solutions offers some MODI Sample, but there is no demo, and not clear if it offer scan solution.

I think solution can be the following – we can configure MSPSCAN.EXE to save scanned images in a certain directory, start MSPSCAN.EXE with OpenProcess API, when it finish – look for a new file in specified directory and use it as scan result. But what I don’t like here –this solution requires a lot of user interaction, so we can get a lot of support calls and the end.

If  you have better idea on this – please drop me a note here.

One more approach - is to use DBPix ActiveX control from Control doing everything we need, besides that it does not support TIFF files.


Anonymous Anonymous said...

Private Function DocScan() As Boolean
On Error GoTo error_DocScan

Dim blnResult As Boolean
Dim WIADevice As WIA.Device
Dim WIAProcess As WIA.ImageProcess
Dim WIAItem As WIA.Item
Dim WIAProperty As WIA.Property
Dim WIAImage As WIA.ImageFile

blnResult = True
Set WIADevice = dmScan.DeviceInfos(1).Connect

If WIADevice.Type = WIA.ScannerDeviceType Then
Set WIAProcess = CreateObject("Wia.ImageProcess")
WIAProcess.Filters.Add WIAProcess.FilterInfos("Convert").FilterID
WIAProcess.Filters(WIAProcess.Filters.Count).Properties("FormatID").Value = _

' This may cause PROBLEMS with ADF-type scanners! May save only the last doc
'WIAItem = WIADevice.Items(1) ' <-- This may be a good solution
For Each WIAItem In WIADevice.Items

' Configure scanner settings
For Each WIAProperty In WIAItem.Properties
Select Case WIAProperty.PropertyID
Case 6146 ' Current Intent
WIAProperty.Value = 4 ' Text or Line Art
Case 6147 ' Horizontal Resolution
WIAProperty.Value = 300 ' 300 DPI
Case 6148 ' Vertical Resolution
WIAProperty.Value = 300 ' 300 DPI
End Select

Set WIAImage = cdScan.ShowTransfer(WIAItem)
Set WIAImage = WIAProcess.Apply(WIAImage)

If (SaveTempFile(WIAImage, m_tempfile)) Then
blnResult = blnResult And True
blnResult = False
MsgBox "Scanning failed to save file"
End If
blnResult = False
MsgBox "Scanner not found"
End If

DocScan = blnResult
Exit Function
DocScan = False
MsgBox "Scanning failed - " & Err.Description
End Function

Private Function SaveTempFile(image As WIA.ImageFile, FileName As String) As Boolean
On Error GoTo error_SaveTempFile

Dim fs As Object
Set fs = CreateObject("Scripting.FileSystemObject")

If fs.FileExists(FileName) Then
fs.DeleteFile FileName, True
End If

image.SaveFile FileName
SaveTempFile = True
Exit Function
SaveTempFile = False
MsgBox "Tempfile not saved - " & Err.Description
End Function

6:58 PM  
Blogger Alex Dybenko said...

Thanks for code!

9:12 PM  
Anonymous Anonymous said...

One small question. can I use MODI with application? If yes then please help me to proceed.

3:30 PM  
Blogger Alex Dybenko said...

From reader:
I found one way one guy done before using the MSPSCAN.EXE he used this command in javascript
the trick is he created a preset in the MSPSCAN.EXE named it Scan and set the options for the scan so whenever you scan, it saves to the folder then delete the file after reading it

var WshShell = new ActiveXObject("WScript.Shell");

WshShell.Exec("C:\\Program Files\\Common Files\\Microsoft Shared\\MODI\\12.0\\MSPSCAN.EXE"+" "+"Scan");

you can use the run command to execute by "C:\Program Files\Common Files\Microsoft Shared\MODI\12.0\MSPSCAN.EXE" scan

but the question is how he knew that the MSPSCAN.EXE can take a parameter for the preset ??i tried to search for a documentation or anything i couldn't find.

1:51 PM  
Anonymous document scanning services said...

Great article about this document scan tips and tricks. Thank you very much.

5:58 AM  
OpenID timduncan81 said...

Great article about this document scan tips and tricks. Thank you very much for sharing it with us.

Miami Best Scanning Of Medical Records

10:53 AM  

Post a Comment

Links to this post:

Create a Link

<< Home