A Python package for digitizing documents from TWAIN, WIA, SANE, ICA and eSCL compatible scanners.
Project description
Python Document Scanner for TWAIN, WIA, SANE, ICA, and eSCL
The package provides methods for calling Dynamsoft Service REST APIs. This allows developers to build Python applications for digitizing documents from TWAIN (32-bit/64-bit), WIA, SANE, ICA and eSCL scanners.
Prerequisites
-
Install Dynamsoft Service.
-
Request a free trial license.
Dynamsoft Service REST API
By default, the REST API's host address is set to http://127.0.0.1:18622
.
Method | Endpoint | Description | Parameters | Response |
---|---|---|---|---|
GET | /DWTAPI/Scanners |
Get a list of scanners | None | 200 OK with scanner list |
POST | /DWTAPI/ScanJobs |
Creates a scan job | license , device , config |
201 Created with job ID |
GET | /DWTAPI/ScanJobs/:id/NextDocument |
Retrieves a document image | id : Job ID |
200 OK with image stream |
DELETE | /DWTAPI/ScanJobs/:id |
Deletes a scan job | id : Job ID |
200 OK |
You can navigate to http://127.0.0.1:18625/
to access the service. To make it accessible from desktop, mobile, and web applications on the same network, you can change the host address to a LAN IP address. For example, you might use http://192.168.8.72
.
The scanner parameter configuration is based on Dynamsoft Web TWAIN documentation.
Quick Start
Replace the license key in the code below with a valid one and run the code.
from dynamsoftservice import ScannerController, ScannerType
scannerController = ScannerController()
devices = []
host = "http://127.0.0.1:18622"
license_key = "LICENSE-KEY"
questions = """
Please select an operation:
1. Get scanners
2. Acquire documents by scanner index
3. Quit
"""
def ask_question():
while True:
print(".............................................")
answer = input(questions)
if answer == '3':
break
elif answer == '1':
scanners = scannerController.getDevices(
host, ScannerType.TWAINSCANNER | ScannerType.TWAINX64SCANNER)
devices.clear()
for i, scanner in enumerate(scanners):
devices.append(scanner)
print(f"\nIndex: {i}, Name: {scanner['name']}")
elif answer == '2':
if len(devices) == 0:
print("Please get scanners first!\n")
continue
index = input(f"\nSelect an index (<= {len(devices) - 1}): ")
index = int(index)
if index < 0 or index >= len(devices):
print("It is out of range.")
continue
parameters = {
"license": license_key,
"device": devices[index]["device"],
}
parameters["config"] = {
"IfShowUI": False,
"PixelType": 2,
"Resolution": 200,
"IfFeederEnabled": False,
"IfDuplexEnabled": False,
}
job_id = scannerController.scanDocument(host, parameters)
if job_id != "":
images = scannerController.getImageFiles(host, job_id, "./")
for i, image in enumerate(images):
print(f"Image {i}: {image}")
scannerController.deleteJob(host, job_id)
else:
continue
if __name__ == "__main__":
ask_question()
Example
DynamsoftService API
The DynamsoftService
class provides methods to interact with the Dynamsoft service.
getDevices(self, host: str, scannerType: int = None) -> List[Any]
: Get a list of available devices.scanDocument(self, host: str, parameters: Dict[str, Any]) -> str
: Scan a document.deleteJob(self, host: str, jobId: str) -> None
: Delete a job.getImageFile(self, host, job_id, directory)
: Get an image file.getImageFiles(self, host: str, jobId: str, directory: str) -> List[str]
: Get a list of image files.getImageStreams(self, host: str, jobId: str) -> List[bytes]
: Get a list of image streams.
How to Build the Package
-
Source distribution:
python setup.py sdist
-
Wheel:
pip wheel . --verbose # Or python setup.py bdist_wheel
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file twain-wia-sane-scanner-1.0.0.tar.gz
.
File metadata
- Download URL: twain-wia-sane-scanner-1.0.0.tar.gz
- Upload date:
- Size: 5.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.18
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 64248859d776b228f2fec5e6d58c5cac82fc7712a61c6f56d5cf5e95f8bed3e7 |
|
MD5 | 0ea17f54c04b1b5cd10fa3fe59750a32 |
|
BLAKE2b-256 | b686d445d6e350e0204ca3b8956084ae53b2e67b02ac8a0b2bb7255221604d9e |
File details
Details for the file twain_wia_sane_scanner-1.0.0-py3-none-any.whl
.
File metadata
- Download URL: twain_wia_sane_scanner-1.0.0-py3-none-any.whl
- Upload date:
- Size: 5.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.18
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e42d40d45709c289af132ea2c4ddd86d637c463c6e8e5649f8c4e951375c2afc |
|
MD5 | 14ab2192db0bd2d3af8ab0c569f03a8c |
|
BLAKE2b-256 | 6fd9b3d6ca4fca2c2e29e5c621749ee918d42a3a3ba561d69b656ed81d421c70 |