Hello World (Read an Image)


Results:
/** LICENSE ALERT - README * To use the library, you need to first specify a license key. * * You can visit https://www.dynamsoft.com/customer/license/trialLicense?utm_source=samples&product=dbr&package=js to get your own trial license good for 30 days. * 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. * For more information, see https://www.dynamsoft.com/barcode-reader/docs/web/programming/javascript/user-guide/index.html#license&utm_source=samples or contact support@dynamsoft.com. * LICENSE ALERT - THE END */ Dynamsoft.License.LicenseManager.initLicense("DLS2eyJoYW5kc2hha2VDb2RlIjoiMjAwMDAwLWRicl9qc19zYW1wbGVzIiwib3JnYW5pemF0aW9uSUQiOiIyMDAwMDAifQ=="); const resultsContainer = document.querySelector("#results"); const pInit = (async () => { const cvRouter = await Dynamsoft.CVR.CaptureVisionRouter.createInstance(); return { cvRouter } })(); document.querySelector("#input-file").addEventListener("change", async function (e) { let file = e.target.files[0]; this.value = ""; resultsContainer.innerText = ""; try { document.querySelector("#decoding").style.display = "inline"; // Show decoding indicator during the decoding process // Decode selected image with 'ReadBarcodes_ReadRateFirst' template. const { cvRouter } = await pInit; const result = await cvRouter.capture(file, "ReadBarcodes_ReadRateFirst"); const barcodeResultItems = result.decodedBarcodesResult?.barcodeResultItems; if (!barcodeResultItems) { resultsContainer.innerText += "No barcode found\n"; return; } for (let item of barcodeResultItems) { resultsContainer.innerText += item.text + "\n"; console.log(item.text); } } catch (ex) { let errMsg = ex.message || ex; console.error(ex); alert(errMsg); } finally { document.querySelector("#decoding").style.display = "none"; // Hide decoding indicator after the decoding process } });