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.

6 comments:

  1. Anonymous6:58 PM

    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

    ReplyDelete
  2. Anonymous3:30 PM

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

    swastik08@gmail.com

    ReplyDelete
  3. 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.

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

    ReplyDelete
  5. Anonymous10:53 AM

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

    Miami Best Scanning Of Medical Records

    ReplyDelete