Skip to content

Instantly share code, notes, and snippets.

@yushulx
Last active June 9, 2025 08:00
Show Gist options
  • Save yushulx/a5f07891d5b22cfd24f21a111c80a008 to your computer and use it in GitHub Desktop.
Save yushulx/a5f07891d5b22cfd24f21a111c80a008 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html>
<body>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/dcv.bundle.min.js"></script>
<input id="input-file" type="file" multiple accept=".jpg,.jpeg,.icon,.gif,.svg,.webp,.png,.bmp" /><br />
Results:<br />
<div id="results"></div>
<div id="parsedrResults" style="width: 100%; min-height: 10vh; font-size: 3vh; overflow: auto"></div>
<script>
const resultsContainer = document.querySelector("#results");
const parsedResultsContainer = document.querySelector("#parsedrResults");
let cvRouter; // an instance of CaptureVisionRouter
let pCvRouter; // promise of CaptureVisionRouter
let parser = null; // an instance of CodeParser
let isSDKReady = false;
document.querySelector("#input-file").addEventListener("change", async function () {
let files = [...this.files];
this.value = "";
resultsContainer.innerText = "";
try {
if (!isSDKReady) {
alert("Please wait for the SDK to load");
return;
}
for (let file of files) {
// Decode selected image with 'ReadSingleBarcode' template.
const result = await cvRouter.capture(file, "ReadBarcodes_Balance")
if (files.length > 1) {
resultsContainer.innerText += `\n${file.name}:\n`;
}
for (let item of result.items) {
if (item.type !== Dynamsoft.Core.EnumCapturedResultItemType.CRIT_BARCODE) {
continue;
}
resultsContainer.innerText += item.text + "\n";
console.log(item.text);
// Parse the Aadhaar
let AADHAAR_Str = item.text;
let parsedResultItem = await parser.parse(AADHAAR_Str);
let parsedResult = JSON.parse(parsedResultItem.jsonString);
let parsedLines = parsedResult.ResultInfo;
console.log(parsedLines)
parsedResultsContainer.innerHTML = "";
parsedLines.forEach((element) => {
resultsContainer.innerHTML +=
"<hr><strong>" + element.FieldName + "</strong><br /><hr>" + element.Value;
});
}
if (!result.items.length) resultsContainer.innerText += "No barcode found\n";
}
} catch (ex) {
let errMsg = ex.message || ex;
console.error(errMsg);
alert(errMsg);
}
});
async function activate() {
try {
await Dynamsoft.License.LicenseManager.initLicense(
"DLS2eyJoYW5kc2hha2VDb2RlIjoiMjAwMDAxLTE2NDk4Mjk3OTI2MzUiLCJvcmdhbml6YXRpb25JRCI6IjIwMDAwMSIsInNlc3Npb25QYXNzd29yZCI6IndTcGR6Vm05WDJrcEQ5YUoifQ==",
true
);
Dynamsoft.Core.CoreModule.loadWasm(["DBR"]);
parser = await Dynamsoft.DCP.CodeParser.createInstance();
await Dynamsoft.DCP.CodeParserModule.loadSpec("AADHAAR");
cvRouter = await Dynamsoft.CVR.CaptureVisionRouter.createInstance();
isSDKReady = true;
}
catch (ex) {
console.error(ex);
}
}
activate();
</script>
</body>
</html>
@vikas990
Copy link

thanks.
its really usefull.

@HemantKumar9500
Copy link

But, your source code is not working Bro..........
plz do it another way ohk

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment