-
Notifications
You must be signed in to change notification settings - Fork 45
Expand file tree
/
Copy pathindex.html
More file actions
106 lines (95 loc) · 3.34 KB
/
index.html
File metadata and controls
106 lines (95 loc) · 3.34 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>
Dynamsoft Barcode Scanner Sample - Scan From Distance
</title>
</head>
<body>
<h1 class="barcode-scanner-title">
Scan From Distance
</h1>
<!-- This div will host the barcode scanner's camera view -->
<div class="barcode-scanner-view"></div>
<!-- Include Dynamsoft Barcode Reader Bundle via CDN -->
<script src="https://cdn.jsdelivr.net/npm/dynamsoft-barcode-reader-bundle@11.2.4000/dist/dbr.bundle.js"></script>
<!-- If the network is unstable or you prefer to self-host the SDK, uncomment the line below to load it locally -->
<!-- <script src="../../../dist/dbr.bundle.js"></script> -->
<script>
// Configuration object for initializing the BarcodeScanner instance. Refer to https://www.dynamsoft.com/barcode-reader/docs/web/programming/javascript/api-reference/barcode-scanner.html#barcodescannerconfig
let config = {
license: "DLS2eyJvcmdhbml6YXRpb25JRCI6IjIwMDAwMSJ9", // Replace with your Dynamsoft license key
container: document.querySelector(".barcode-scanner-view"), // Specify where to render the scanner UI
scanMode: Dynamsoft.EnumScanMode.SM_MULTI_UNIQUE,
showUploadImageButton: true,
scannerViewConfig: {
showFlashButton: true,
cameraSwitchControl: "toggleFrontBack",
},
templateFilePath: './ReadDistantBarcodes.json',
utilizedTemplateNames: {
"single": "ReadDistantBarcodes",
"multi_unique": "ReadDistantBarcodes",
"image": "ReadDistantBarcodes"
},
onInitReady: (components) => {
// Set the scan region to a rectangle with percentage values by cameraEnhancer
let region = {
"left": 25,
"right": 75,
"top": 25,
"bottom": 75,
"isMeasuredInPercentage": true
};
components.cameraEnhancer.setScanRegion(region);
},
// The watermark can be removed via showPoweredByDynamsoft configuration option.
// showPoweredByDynamsoft: false,
};
// Create a new instance of the Dynamsoft Barcode Scanner
const barcodeScanner = new Dynamsoft.BarcodeScanner(config);
// Launch the scanner and handle the scanned result
barcodeScanner.launch().then((result) => {
// Display the first detected barcode's text in an alert
if (result.barcodeResults.length) {
alert(result.barcodeResults[0].text);
} else {
alert("No barcode found");
}
});
</script>
<!--
Please note that putting CSS at the end is not a best practice.
We do this so that you can focus on reading the JS logic.
-->
<style>
/* Reset default margin and padding, and apply border-box sizing */
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
/* Ensure html and body take full viewport size */
html,
body {
width: 100%;
height: 100%;
}
/* Style for the scanner title */
.barcode-scanner-title {
height: 80px;
text-align: center;
font-size: 20px;
padding: 20px 0;
}
/* Container where the barcode scanner will be rendered */
.barcode-scanner-view {
width: 100%;
height: calc(100% - 80px);
/* Fill remaining space below the title */
}
</style>
</body>
</html>