Scanner.js acquires images from TWAIN WIA scanners and webcams in your browser. The output can be returning the images to the web page, uploading to the server directly, or in your case, saving to the local disk.
<html lang="en">
<head>
<script src="//asprise.azureedge.net/scannerjs/scanner.js" type="text/javascript"></script>
<script>
function scanToLocalDisk() {
scanner.scan(displayResponseOnPage,
{
"twain_cap_setting" : {
"ICAP_PIXELTYPE" : "TWPT_RGB", // Color
"ICAP_SUPPORTEDSIZES" : "TWSS_USLETTER" // Paper size: TWSS_USLETTER, TWSS_A4, ...
},
"output_settings": [
{
"type": "save",
"format": "pdf",
"save_path": "C:\\myfolder\\${TMS}${EXT}"
}
]
}
);
}
function displayResponseOnPage(successful, mesg, response) {
if(!successful) { // On error
document.getElementById('response').innerHTML = 'Failed: ' + mesg;
return;
}
if(successful && mesg != null && mesg.toLowerCase().indexOf('user cancel') >= 0) { // User cancelled.
document.getElementById('response').innerHTML = 'User cancelled';
return;
}
document.getElementById('response').innerHTML = scanner.getSaveResponse(response);
}
</script>
</head>
<body>
<h2>Scan to Local Disk</h2>
<button type="button" onclick="scanToLocalDisk();">Scan</button>
<div id="response"></div>
</body> </html>
When specifying the value for save_path
, you may use variables which will be expanded. For example, ${TMS} will be expanded as timestamp and ${EXT} as file extension.
Scanner.js supports in browser web twain image acquisition in formats like JPG, multi-page PDF, PNG, etc.
Read the developer guide to JavaScript web twain scanning for browsers (Chrome, Edge, Firefix and IE).