Last active
August 20, 2018 06:19
-
-
Save yushulx/74d0098b35a3d57f6125da2aed866280 to your computer and use it in GitHub Desktop.
How to use Dynamsoft Pure JavaScript barcode SDK
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
</head> | |
<body> | |
<div id="divLoadInfo">loading...</div> | |
<input id="uploadImage" type="file" accept="image/bmp,image/jpeg,image/png,image/gif"> | |
<script src="https://demo.dynamsoft.com/dbr_wasm/js/dbr-6.3.0.min.js"></script> | |
<script> | |
dynamsoft = self.dynamsoft || {}; | |
dynamsoft.dbrEnv = dynamsoft.dbrEnv || {}; | |
// change it when you put dynamsoft.barcodereader.wasm other place | |
// case you put dynamsoft.barcodereader.wasm in 'js/dynamsoft.barcodereader.wasm', set this 'js' | |
dynamsoft.dbrEnv.resourcesPath = 'https://demo.dynamsoft.com/dbr_wasm/js/'; | |
dynamsoft.dbrEnv.onAutoLoadWasmSuccess = function(){ | |
document.getElementById('divLoadInfo').innerHTML="load dbr wasm success."; | |
}; | |
dynamsoft.dbrEnv.onAutoLoadWasmError = function(status){ | |
document.getElementById('divLoadInfo').innerHTML="load wasm failed: "+status; | |
}; | |
//https://www.dynamsoft.com/CustomerPortal/Portal/TrialLicense.aspx | |
dynamsoft.dbrEnv.licenseKey = "t0068MgAAAD2IrA1WJjiVx78RfaZ46qMyCY8DaqpvAD57z5QWkwVQkVwZEf7lE+M2QYbnPx9Fu/aFvCL1mz0Kh2YK0milUng="; | |
</script> | |
<script> | |
document.getElementById('uploadImage').addEventListener('change', function(){ | |
var files = this.files; | |
var reader = new dynamsoft.BarcodeReader(); | |
reader.decodeFileInMemory(files[0]).then(function(results){ | |
var txts = []; | |
for(var i=0;i<results.length;++i){ | |
txts.push(results[i].BarcodeText); | |
} | |
alert(txts.join("\n")); | |
}).catch(ex=>{ | |
console.log(ex); | |
}); | |
this.value = ''; | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment