|
| 1 | +<!DOCTYPE html> |
| 2 | +<html lang="en"> |
| 3 | + <head> |
| 4 | + <meta charset="UTF-8" /> |
| 5 | + <meta name="viewport" content="width=device-width, initial-scale=1.0" /> |
| 6 | + <meta |
| 7 | + name="description" |
| 8 | + content="Read barcodes from camera with Dynamsoft Barcode Reader and update settings for dense codes." |
| 9 | + /> |
| 10 | + <meta name="keywords" content="read barcode from camera, dense" /> |
| 11 | + <link |
| 12 | + rel="canonical" |
| 13 | + href="https://demo.dynamsoft.com/Samples/DBR/JS/3.settings/6.dense-barcodes.html" |
| 14 | + /> |
| 15 | + <title>Dynamsoft Barcode Reader Sample - Dense Barcodes</title> |
| 16 | + <!-- |
| 17 | + This sample makes use of the library hosted by the CDN jsDelivr. If you would rather use the |
| 18 | + library offline. Please see the guide on how to host the library: |
| 19 | + https://www.dynamsoft.com/barcode-reader/programming/javascript/user-guide/?ver=latest#host-the-library-yourself-recommended |
| 20 | + --> |
| 21 | + <script src="https://cdn.jsdelivr.net/npm/dynamsoft-javascript-barcode@9.2.13/dist/dbr.js"></script> |
| 22 | + </head> |
| 23 | + <body> |
| 24 | + <div id="div-ui-container" style="width: 100%; height: 70vh"></div> |
| 25 | + <textarea |
| 26 | + id="textarea-results" |
| 27 | + style="width: 100%; height: 20vh;margin-top: 20px;" |
| 28 | + ></textarea> |
| 29 | + <script> |
| 30 | + /** LICENSE ALERT - README |
| 31 | + * To use the library, you need to first specify a license key using the API "license" as shown below. |
| 32 | + */ |
| 33 | + |
| 34 | + Dynamsoft.DBR.BarcodeReader.license = |
| 35 | + "DLS2eyJvcmdhbml6YXRpb25JRCI6IjIwMDAwMSJ9"; |
| 36 | + |
| 37 | + /** |
| 38 | + * You can visit https://www.dynamsoft.com/customer/license/trialLicense?utm_source=github&product=dbr&package=js to get your own trial license good for 30 days. |
| 39 | + * Note that if you downloaded this sample from Dynamsoft while logged in, the above license key may already be your own 30-day trial license. |
| 40 | + * For more information, see https://www.dynamsoft.com/barcode-reader/programming/javascript/user-guide/?ver=9.2.13&utm_source=github#specify-the-license or contact support@dynamsoft.com. |
| 41 | + * LICENSE ALERT - THE END |
| 42 | + */ |
| 43 | + |
| 44 | + const textareaResults = document.querySelector("#textarea-results"); |
| 45 | + |
| 46 | + let scanner; |
| 47 | + |
| 48 | + (async () => { |
| 49 | + try { |
| 50 | + scanner = await Dynamsoft.DBR.BarcodeScanner.createInstance(); |
| 51 | + |
| 52 | + // Get ui by 'getUIElement()' and append it to DOM. |
| 53 | + document |
| 54 | + .querySelector("#div-ui-container") |
| 55 | + .append(scanner.getUIElement()); |
| 56 | + |
| 57 | + /** |
| 58 | + * 'onFrameRead' is triggered after the library finishes reading a frame image. |
| 59 | + * There can be multiple barcodes on one image. |
| 60 | + */ |
| 61 | + scanner.onFrameRead = (results) => { |
| 62 | + textareaResults.value = ""; |
| 63 | + for (let result of results) { |
| 64 | + const format = result.barcodeFormat |
| 65 | + ? result.barcodeFormatString |
| 66 | + : result.barcodeFormatString_2; |
| 67 | + const text = result.barcodeText; |
| 68 | + textareaResults.value += `${format}: ${text}\n`; |
| 69 | + } |
| 70 | + }; |
| 71 | + |
| 72 | + // Use template 'dense' for decoing dense barcodes and set high resolution. |
| 73 | + await scanner.updateRuntimeSettings("dense"); |
| 74 | + await scanner.setResolution(3840, 2160); |
| 75 | + |
| 76 | + /** |
| 77 | + * 'open()' opens the camera. |
| 78 | + * After that, the library starts to scan the frame images continuously. |
| 79 | + */ |
| 80 | + await scanner.open(); |
| 81 | + } catch (ex) { |
| 82 | + let errMsg; |
| 83 | + if (ex.message.includes("network connection error")) { |
| 84 | + errMsg = |
| 85 | + "Failed to connect to Dynamsoft License Server: network connection error. Check your Internet connection or contact Dynamsoft Support (support@dynamsoft.com) to acquire an offline license."; |
| 86 | + } else { |
| 87 | + errMsg = ex.message || ex; |
| 88 | + } |
| 89 | + console.error(errMsg); |
| 90 | + alert(errMsg); |
| 91 | + } |
| 92 | + })(); |
| 93 | + </script> |
| 94 | + </body> |
| 95 | +</html> |
0 commit comments