Allows your web application to communicate with a scanner and receive scanned images.
- Make sure you have Python 2.7 is installed.
- Make sure cmd
pip
is recognized, else, add Python to your system's PATH. - Download & install the TWAIN python module.
- Execute
pip install image
(responsible for serving images) - Execute
pip install tornado
(responsible for opening a web server) - Execute
pip install wxPython
(responsible for the app to become a tray icon) - Navigate to the project folder and execute
app.py
.
-
In command prompt, navigate to the project's root and run
app.py
. -
Make sure
app.py
is serving. -
In your web application(s), call a simple Ajax GET request to localhost:8087 (see below section).
All communicaction are in HTTPS GET requests format.
/scan
Description
Selects the first scanner the app finds and begins the scanning call.
Request example
$.support.cors = true;
$.ajax({
crossDomain: true,
type : "GET",
url : "https://localhost:8087/scan",
dataType : "json",
success : function(response) {
console.log(response.data) // base64 encoded image
},
});
Response example
String. Base64 encoded string of a single JPEG image.
/multi-scan
Description
Selects the first scanner the app finds and begin scanning until all papers are scanned.
Request example
$.support.cors = true;
$.ajax({
crossDomain: true,
type : "GET",
url : "https://localhost:8087/multi-scan",
success : function(response) {
console.log(response.data.images); // An array of base64 encoded strings.
console.log('total:' + response.data.total); // Total images scanned.
},
});
Example response
{
'images': {
base64 encoded string,
base64 encoded string,
...
},
'total': 10
}
/get-scanners
Description
Gets a list of scanners detected.
Request example
{
'scanner-name': 'scanner-name',
'scanner-name1': 'scanner-name1',
...
}
- Run
python setup.py py2exe
- Once compiled, navigate to
dist
, and openapp.exe
.
If you plan to take app.exe somewhere else, it must have the folder 'cert' next to it with the certificate files.
In app.py
, you will find the function setScanner
, use that.
Call the route /get-scanners
.
Often times web-applications need to benefit from connecting to scanners.
It's virtually impossible if we take a direct route to a scanner via DLL located on clients' computers, because web browsers don't have permission to utilize those resources.
Sometimes it is often suggested to use:
-
ActiveX: Allows you to communicate directly with DLLs. It propriety code, limited to IE, and has security problems.
-
Java applets: Communicate directly with DLLs. Except, the support of Java applets is dying. Chrome/FF don't support this anymore.
-
Silverlight / Flash... no.
Have a 'Web Agent' which acts as a local server that accepts HTTP requests.
Based on the HTTP requests, we call the appropiate DLL or execute commands.
A web agent is a link between the browser and the internals of the computer.
Further read: https://wicg.github.io/webusb/ - Chrome's WebUSB API. This also limited to Chrome.
- Allow user to select which scanner to choose from.
- A GUI for the web agent.
- Web agent can be minimized to tray.
- Allow web agent to be added to the system's startup & be minimized on boot.
- Work on API.
This project will use Sphinx.
This package is open-sourced software licensed under the MIT license.
saochishti - https://github.com/soachishti/pyScanLib
chmuche - https://github.com/ndp-systemes/pyScanLib (multi-page scan code)