-1

I am building an application with python that needs to be able to connect to a scanner and process the data from the resulting pdf/jpeg/whatever. I have been trying to find a way to connect to the scanner to request a scan, but with no real progress.

I have looked around at all the options I could find, including this answer : I want to connect my program to image scanner

Most of the solutions I have found say that you need to use pyTwain, pySane, Libinsane, python-imagescanner, or the likes, which all seem to revolve around using TWAIN for Windows or SANE for Linux. I have a printer/scanner combo, but I can't find a TWAIN driver for it since it is not an 'enterprise' printer, but even then I don't know that this specific printer is what users would have, so I am looking for a more general solution.

The confusing part for me, is that I can still get the scanner to scan just fine by using Windows Fax and Scan, so I feel like there must be a way to get the scanner to receive a scan command from programs.

I don't really need much control over the scanner, just "scan the image and save the file here ___". So, is there any way to just tell Windows to send the "scan" command and save the output to a specific file that I can access? Maybe just using like a command through os.system()? (Basically, if windows can do it, can't I just use windows tools?)

A way to do this through linux would be helpful, too, but Windows 10 is the primary concern.

Entest89
  • 77
  • 5
  • I don't think this is actually a python question at all. It is more about a specific printer manufacturer as ultimately it's up to them. Have you taken a look at what they recommend? You can find the link to their dev page here: https://developers.hp.com/tools – Emir Nov 09 '21 at 23:40
  • I tried to not mention specifics about the scanner because I want something more general. Some way to just use the windows tools from Python. I tried to update the question to make more sense. – Entest89 Nov 10 '21 at 00:27
  • If you want to use command line tools, that decouples your question from Python entirely and makes it a general usage question that could go on Super User instead of Stack Overflow. – Charles Duffy Nov 10 '21 at 03:27

1 Answers1

2

I cannot answer for Linux only for Windows.

The generic method to talk to a scanner is via Windows Image Acquisition.

In most cases the scanner needs some driver support and that's usually easily confirmed via MsPaint scanning (or if it is installed Fax scanning).

So first check the scanner in included in Windows Devices and either right click scan OR attempt a scan in Paint.

If you see messages like these the client is not enabled to use the scanner via WIA and you will need to install a suitable WIA driver.

enter image description here

Once that hurdle is surmounted then you can use a WIA-CMD-Scanner app to try to acquire the image to a file using https://github.com/nagimov/wia-cmd-scanner , it is a small 35 KB compiled VB exe.

So in my testing that scanner only returns a full platen scan 21.59 cm x 29.70 cm (it would not respect reducing the scan area with this tool.) NOTE also it only works with the first scanner, as found by Windows (You would need to modify the code for targeting a specific model).

The command that works for me (YMMV)

wia-cmd-scanner.exe  /w 0 /h 0 /dpi 300 /color RGB /format PNG /output .\scan.png

Scanning to file .\scan.png (dpi = 300, color mode 'RGB', output format 'PNG')
Scan finished in 27 seconds

There is an example of setting date / using for loop in the readme https://github.com/nagimov/wia-cmd-scanner#scripting-and-automation

K J
  • 8,045
  • 3
  • 14
  • 36