191 lines
5.0 KiB
HTML
191 lines
5.0 KiB
HTML
<!DOCTYPE html>
|
||
<html>
|
||
<head>
|
||
<title>Test!</title>
|
||
<meta charset="utf-8"/>
|
||
<script type="text/javascript" src="psl.sane.webapi.min 2.1.0.js" charset="utf-8"></script>
|
||
</head>
|
||
<body>
|
||
<p>
|
||
<h1>Test!</h1>
|
||
<select id="devicenames" style="width:200px; height:25px;">
|
||
</select>
|
||
<input id="getdevices" type="button" value="获取设备列表" onclick="getdevices()" /><br>
|
||
<input id="scan" type="button" value="扫描" onclick="scan()" /><br>
|
||
<input id="getsettinginfo" type="button" value="获取扫描参数" onclick="getsettinginfo()" /><br>
|
||
<input id="converttobase64" type="button" value="转换Base64" onclick="converttobase64()" /><br>
|
||
</p>
|
||
<p>
|
||
<img id="myCanvas" width='640' height='480' style="background-color: black;"/>
|
||
</p>
|
||
<p>
|
||
<input type="text" id="pathinfo" style="width:640px; height:40px;" />
|
||
</p>
|
||
<p>
|
||
<input type="text" id="errinfo" style="width:640px; height:40px;" />
|
||
</p>
|
||
<script>
|
||
|
||
function onGetDevicesFunc(devs)
|
||
{
|
||
//alert(JSON.stringify(devs));
|
||
|
||
var select = document.getElementById('devicenames');
|
||
select.innerHTML = "";
|
||
for (var i = 0; i < devs.length; ++i)
|
||
{
|
||
var option = document.createElement('option');
|
||
option.value = devs[i]['Name'];
|
||
option.textContent = devs[i]['Name'];
|
||
select.appendChild(option);
|
||
}
|
||
}
|
||
|
||
function onDetectDevicesFunc(devs)
|
||
{
|
||
//alert(JSON.stringify(devs));
|
||
|
||
var select = document.getElementById('devicenames');
|
||
select.innerHTML = "";
|
||
for (var i = 0; i < devs.length; ++i)
|
||
{
|
||
var option = document.createElement('option');
|
||
option.value = devs[i]['Name'];
|
||
option.textContent = devs[i]['Name'];
|
||
select.appendChild(option);
|
||
}
|
||
}
|
||
|
||
function onGetSettingInfoFunc(optList)
|
||
{
|
||
alert(optList);
|
||
}
|
||
|
||
function onGetBase64Func(base64)
|
||
{
|
||
if (base64)
|
||
{
|
||
var myCanvas = document.getElementById("myCanvas");
|
||
myCanvas.src = "data:image/png;base64," + base64;
|
||
}
|
||
}
|
||
|
||
function onScanOneFileDoneFunc(datatype, liveDetect, imgfmt, imgpath, imgbase64data)
|
||
{
|
||
if (imgpath)
|
||
{
|
||
var pathinfo = document.getElementById('pathinfo');
|
||
pathinfo.value = imgpath;
|
||
}
|
||
|
||
if (imgbase64data)
|
||
{
|
||
var myCanvas = document.getElementById("myCanvas");
|
||
myCanvas.src = "data:image/jpeg;base64," + imgbase64data;
|
||
}
|
||
}
|
||
|
||
function onScanAllFilesDoneFunc(str)
|
||
{
|
||
alert(str);
|
||
}
|
||
|
||
function onScanMultiPagesFileDoneFunc(imgfmt, imgpath)
|
||
{
|
||
if (imgpath)
|
||
{
|
||
var pathinfo = document.getElementById('pathinfo');
|
||
pathinfo.value = imgpath;
|
||
}
|
||
}
|
||
|
||
function onErrorMessageFunc(errormsg)
|
||
{
|
||
var errinfo = document.getElementById('errinfo');
|
||
errinfo.value = errormsg;
|
||
}
|
||
|
||
function getdevices()
|
||
{
|
||
var errinfo = document.getElementById('errinfo');
|
||
errinfo.value = "";
|
||
|
||
psl.sane.getdevices();
|
||
}
|
||
|
||
function scan()
|
||
{
|
||
var pathinfo = document.getElementById('pathinfo');
|
||
pathinfo.value = "";
|
||
var errinfo = document.getElementById('errinfo');
|
||
errinfo.value = "";
|
||
var myCanvas = document.getElementById("myCanvas");
|
||
myCanvas.src = 'placeholder.png';
|
||
|
||
psl.sane.showbase64 = 1;
|
||
psl.sane.source = "Adf-duplex";
|
||
psl.sane.mode = "Color";
|
||
psl.sane.resolution = "200";
|
||
psl.sane.deletefilesbeforescan = 1;
|
||
psl.sane.filepath = "D:\\123456";
|
||
psl.sane.fileprefix = "KKKKKK";
|
||
psl.sane.filetype = 3;
|
||
psl.sane.pageauto = 1;
|
||
psl.sane.papersize = "A4";
|
||
psl.sane.blankpageskip = 0;
|
||
psl.sane.blankpageskipsensitivity = 3;
|
||
psl.sane.multifeeddetection = "Stop";
|
||
|
||
psl.sane.scan(document.getElementById('devicenames').value);
|
||
}
|
||
|
||
function getsettinginfo()
|
||
{
|
||
var errinfo = document.getElementById('errinfo');
|
||
errinfo.value = "";
|
||
|
||
psl.sane.getsettinginfo(document.getElementById('devicenames').value);
|
||
}
|
||
|
||
function converttobase64()
|
||
{
|
||
var pathinfo = document.getElementById('pathinfo');
|
||
pathinfo.value = "";
|
||
var errinfo = document.getElementById('errinfo');
|
||
errinfo.value = "";
|
||
var myCanvas = document.getElementById("myCanvas");
|
||
myCanvas.src = 'placeholder.png';
|
||
|
||
psl.sane.converttobase64('D:\\1.png');
|
||
}
|
||
|
||
window.onload = function()
|
||
{
|
||
var pathinfo = document.getElementById('pathinfo');
|
||
pathinfo.value = "";
|
||
var errinfo = document.getElementById('errinfo');
|
||
errinfo.value = "";
|
||
var myCanvas = document.getElementById("myCanvas");
|
||
myCanvas.src = 'placeholder.png';
|
||
|
||
psl.sane.registerevent("OnGetDevices", onGetDevicesFunc);
|
||
psl.sane.registerevent("OnDetectDevices", onDetectDevicesFunc);
|
||
psl.sane.registerevent("OnGetSettingInfo", onGetSettingInfoFunc);
|
||
psl.sane.registerevent("OnGetBase64", onGetBase64Func);
|
||
psl.sane.registerevent("OnScanOneFileDone", onScanOneFileDoneFunc);
|
||
psl.sane.registerevent("OnScanAllFilesDone", onScanAllFilesDoneFunc);
|
||
psl.sane.registerevent("OnScanMultiPagesFileDone", onScanMultiPagesFileDoneFunc);
|
||
psl.sane.registerevent("OnErrorMessage", onErrorMessageFunc);
|
||
|
||
psl.sane.init(23165, true);
|
||
}
|
||
|
||
window.onbeforeunload = function()
|
||
{
|
||
|
||
}
|
||
|
||
</script>
|
||
</body>
|
||
</html>
|