scanning under windows WIA with custom settings (dpi / etc )

News123 news123 at free.fr
Sat Nov 28 16:18:35 EST 2009


Meanwhile I found out, why my script worked only on windows 7/Vista and
not on my XP host.

The WIA 2.0 Scripting Model is by default not installed on Windows XP.

Install instructions can be found at
http://msdn.microsoft.com/en-us/library/ms630827%28VS.85%29.aspx


My second problem (changing parameters) is still not solved in python.

bye

N

News123 wrote:
> Hi,
> 
> I'm trying to scan a document from a python 2.6 script without user
> interaction.
> 
> I found  a code snippet, that allows me to scan under Vista, but that
> doesn't allow me to select the dpi / color mode / etc.
> 
> The snippet uses win32com.client
> 
> # ##################### script start
> import win32com.client,os
> 
> WIA_IMG_FORMAT_PNG       = "{B96B3CAF-0728-11D3-9D7B-0000F81EF32E}"
> WIA_COMMAND_TAKE_PICTURE = "{AF933CAC-ACAD-11D2-A093-00C04F72DC3C}"
> 
> os.chdir('c:/temp')
> wia = win32com.client.Dispatch("WIA.CommonDialog")
> dev = wia.ShowSelectDevice()
> for command in dev.Commands:
>     if command.CommandID==WIA_COMMAND_TAKE_PICTURE:
>         foo=dev.ExecuteCommand(WIA_COMMAND_TAKE_PICTURE)
> i=1
> for item in dev.Items:
>     if i==dev.Items.Count:
>         image=item.Transfer(WIA_IMG_FORMAT_PNG)
>         break
>     i=i+1
> 
> image.SaveFile("test.png")
> ######################### script end
> 
> 
> My problems are:
> 
> - This script works fine for me under Windows 7, however I'm
>   unable to   specify additional parameters, like dpi and
>   color mode.
> 
> - The script doesn't work under windows XP, though the scanner driver is
> installed. (Gimp finds the scanner (as WIA scanner)).
> Perhaps 'WIA.CommonDialig' has another name or I need to install some DLL.
> The error message is:
> --------------------------------------------------------------------
> Traceback (most recent call last):
>   File "C:\work\python\minidemos\wia_get_simple.py", line 7, in <module>
>     wia = win32com.client.Dispatch("WIA.CommonDialog")
>   File "C:\Python26\lib\site-packages\win32com\client\__init__.py", line
> 95, in Dispatch
>     dispatch, userName =
> dynamic._GetGoodDispatchAndUserName(dispatch,userName,clsctx)
>   File "C:\Python26\lib\site-packages\win32com\client\dynamic.py", line
> 104, in _GetGoodDispatchAndUserName
>     return (_GetGoodDispatch(IDispatch, clsctx), userName)
>   File "C:\Python26\lib\site-packages\win32com\client\dynamic.py", line
> 84, in _GetGoodDispatch
>     IDispatch = pythoncom.CoCreateInstance(IDispatch, None, clsctx,
> pythoncom.IID_IDispatch)
> com_error: (-2147221005, 'Invalid class string', None, None)
> ---------------------------------------------------------------------






More information about the Python-list mailing list