Reading Driver’s License Information from PDF417 in JavaScript

Xiao Ling
2 min readJun 24, 2020

--

A few weeks ago, I wrote an article sharing how to read driver’s license information from PDF417 on Android. Comparing to building an Android native camera app, building a web camera app is much easier. In this article, let’s take a glimpse at a JavaScript sample, which is implemented with a few lines of code by invoking Dynamsoft JavaScript barcode SDK.

JS Barcode SDK Installation

The JavaScript barcode library is available for download on npmjs.org.

You can either download the package via

npm install dynamsoft-javascript-barcode --save

or include the online JS file directly:

<script src="https://cdn.jsdelivr.net/npm/dynamsoft-javascript-barcode@7.4.0-v1/dist/dbr.js" data-productKeys="PRODUCT-KEYS"></script>

Building a Web Barcode Reader in less than 30 Seconds

Dynamsoft JavaScript barcode SDK is based on WebAssembly, which brings the high performance of barcode scanning functionality to web developers. Besides, it provides built-in camera module APIs. With the deeply encapsulated JavaScript SDK, you will find making an HTML5 barcode reader with cameras can never be such convenient.

To quickly build a web barcode reader, you just need to copy the following code to your HTML file:

Note: you have to get a free trial license to substitute the PRODUCT-KEYS.

If you have updated Microsoft Edge, Chrome, or Firefox to the latest version, you just need to open the HTML file by double-clicking rather than make any web server deployment.

Parsing Driver’s License Information Based on AAMVA Standard

For better balance the accuracy and performance of decoding PDF417 symbology, you’d better make some parameter configurations according to the online documentation:

let runtimeSettings = await scanner.getRuntimeSettings(); runtimeSettings.barcodeFormatIds = Dynamsoft.EnumBarcodeFormat.BF_PDF417; runtimeSettings.LocalizationModes = [2,8,0,0,0,0,0,0]; runtimeSettings.deblurLevel = 2; await scanner.updateRuntimeSettings(runtimeSettings);

The last thing is to create a JavaScript parser for extracting driver’s license information based on the AAMVA standard:

To save time, you can use alert() to show driver’s license information:

scanner.onUnduplicatedRead = txt => {let licenseInfo = parseDriverLicense(txt);alert(JSON.stringify(licenseInfo));};

Source Code

https://github.com/yushulx/javascript-driver-license

Originally published at https://www.dynamsoft.com on June 24, 2020.

--

--

Xiao Ling

Manager of Dynamsoft Open Source Projects | Tech Lover