Alex & Access

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

About Me Search
My Photo
Name:Alex Dybenko

Location:Moscow, Russia
Google
 
Web AccessBlog.net

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 Ammara.com. Control doing everything we need, besides that it does not support TIFF files.

3 Comments:

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 = _
WIA.wiaFormatTIFF

' 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
DoEvents

' 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
Next

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

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

DocScan = blnResult
Exit Function
error_DocScan:
DocScan = False
MsgBox "Scanning failed - " & Err.Description
Err.Clear
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
error_SaveTempFile:
SaveTempFile = False
MsgBox "Tempfile not saved - " & Err.Description
Err.Clear
End Function

6:58 PM  
Blogger Alex Dybenko said...

Thanks for code!

9:12 PM  
Anonymous Anonymous said...

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

swastik08@gmail.com

3:30 PM  

Post a Comment

Links to this post:

Create a Link

<< Home