-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathhelloworld.html
More file actions
108 lines (100 loc) · 4.99 KB
/
helloworld.html
File metadata and controls
108 lines (100 loc) · 4.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Hello World</title>
<script src="Resources/dynamsoft.webtwain.config.js"></script>
<script src="Resources/dynamsoft.webtwain.initiate.js"></script>
</head>
<body>
<div>SelectService:<select size="1" id="selServices" style="position: relative; width: 240px;" onchange="onServiceSelected();"></select></div>
<div>SelectSource:<select size="1" id="selDevices" style="position: relative; width: 240px;"></select></div>
<div><button onclick="AcquireImage();">Scan</button></div>
<div id="dwtcontrolContainer" style="width: 350px; height: 380px;"></div>
<script type="text/javascript">
var DWRemoteScanObject, allServices, allDevices;
var serverurl = 'http://demo.scannerproxy.com/'; // A public proxy server provided by Dynamsoft. You can also change to your own proxy server.
Dynamsoft.DWT.AutoLoad = false; // Disable the loading of Web TWAIN
Dynamsoft.DWT.ProductKey = "DLS2eyJvcmdhbml6YXRpb25JRCI6IjIwMDAwMSJ9"; // Public trial license which is valid for 24 hours
Dynamsoft.DWT.CreateRemoteScanObjectAsync(serverurl)
.then(function (rsObject) {
DWRemoteScanObject = rsObject;
var element = document.getElementById("dwtcontrolContainer");
DWRemoteScanObject.Viewer.bind(element); // viewer bind element xxx
DWRemoteScanObject.Viewer.show(); // viewer show
return DWRemoteScanObject.getServices();
})
.then(function (services) {
allServices = services;
var ddlService = document.getElementById("selServices");
if (ddlService) {
ddlService.options.length = 0;
ddlService.options.add(new Option("--select a service--", "-1"));
for (var i = 0; i < services.length; i++) {
var serverInfo = services[i];
if (serverInfo.attrs.name.length > 0)
ddlService.options.add(new Option(serverInfo.attrs.name, i));
else ddlService.options.add(new Option(serverInfo.attrs.UUID, i));
}
ddlService.selectedIndex = 0;
}
})
.catch(function (exp) {
console.error(exp);
});
function onServiceSelected() {
var ddlService = document.getElementById("selServices");
if (ddlService.selectedIndex >= 0 && allServices && allServices.length > 0) {
var devicetype =
Dynamsoft.DWT.EnumDWT_DeviceType.TWAINSCANNER |
Dynamsoft.DWT.EnumDWT_DeviceType.WIASCANNER |
Dynamsoft.DWT.EnumDWT_DeviceType.TWAINX64SCANNER |
Dynamsoft.DWT.EnumDWT_DeviceType.ICASCANNER |
Dynamsoft.DWT.EnumDWT_DeviceType.SANESCANNER |
Dynamsoft.DWT.EnumDWT_DeviceType.ESCLSCANNER |
Dynamsoft.DWT.EnumDWT_DeviceType.WIFIDIRECTSCANNER;
DWRemoteScanObject.getDevices({
serviceInfo: allServices[ddlService.selectedIndex - 1],
deviceType: devicetype,
})
.then(function (devices) {
allDevices = devices;
var ddlDevice = document.getElementById("selDevices");
if (ddlDevice) {
ddlDevice.options.length = 0;
ddlDevice.options.add(new Option("--select a device--", "-1"));
for (var i = 0; i < devices.length; i++) {
var device = devices[i];
if (device.displayName.length > 0)
ddlDevice.options.add(new Option(device.displayName, i));
else ddlDevice.options.add(new Option(device.name, i));
}
ddlDevice.selectedIndex = 0;
}
})
.catch(function (exp) {
console.error(exp);
});
}
}
function AcquireImage() {
if (DWRemoteScanObject) {
var selDevices = document.getElementById("selDevices");
if (selDevices) {
if (selDevices.selectedIndex - 1 >= 0) {
DWRemoteScanObject.acquireImage(
allDevices[selDevices.selectedIndex - 1],
{
IfCloseSourceAfterAcquire: true, // Scanner source will be closed automatically after the scan.
}
).catch(function (exp) {
alert(exp.message);
});
}
}
}
}
</script>
</body>
</html>