UNPKG

scandit-sdk

Version:

Scandit Barcode Scanner SDK for the Web

78 lines (72 loc) 2.33 kB
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8" /> <title>Scandit Example Page</title> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <script src="build/browser/index.min.js"></script> <!-- The following is only an example style for the container element and other demo elements, it's not required --> <style> body { background-color: black; color: white; font-family: Arial, "Helvetica Neue", Helvetica, sans-serif; } .scanner { position: absolute; top: 0; bottom: 0; left: 0; right: 0; margin: auto; max-width: 1280px; max-height: 80%; } .result-text { padding: 1rem; font-size: 18pt; text-align: center; white-space: pre; font-family: monospace; } </style> </head> <body> <div id="scandit-barcode-picker" class="scanner"></div> <div id="scandit-barcode-result" class="result-text"></div> <script> ScanditSDK.configure("YOUR_LICENSE_KEY_IS_NEEDED_HERE", { engineLocation: "build", }) .then(() => { return ScanditSDK.BarcodePicker.create(document.getElementById("scandit-barcode-picker"), { playSoundOnScan: true, vibrateOnScan: true, scanSettings: new ScanditSDK.ScanSettings({ enabledSymbologies: ["ean8", "ean13", "upca", "upce", "code128", "code39", "code93", "itf"], codeDuplicateFilter: 1000, }), }).then((barcodePicker) => { barcodePicker .on("scan", (scanResult) => { document.getElementById("scandit-barcode-result").innerHTML = scanResult.barcodes.reduce( (string, barcode) => { return `${string}${ScanditSDK.Barcode.Symbology.toHumanizedName(barcode.symbology)}: ${ barcode.data }<br/>`; }, "" ); }) .on("scanError", (error) => { console.error(error); }); }); }) .catch((error) => { console.error(error); alert(error); }); </script> </body> </html>