Parsing pdf417 aamvaid in c#

1.8k Views Asked by At

I am attempting to read the back of a driver's license to decode the pdf417 barcode on the back. I tried using zxing.net with the following code:

var reader = new BarcodeReader();
reader.Options.PossibleFormats = new List<BarcodeFormat>() { BarcodeFormat.PDF_417 };
var barcodeBitmap = (Bitmap)Image.FromFile("bc.png");
var result = reader.Decode(barcodeBitmap);

The image is a test image I grabbed from the internet:

pdf 417 test image

I am able to parse out the PDF417 barcode but how do I get the actual driver's license data from this?

@ ANSI 6360050101DL00300203DLDAQ3265188 DAALOTT,ERIC,B, DAG763 TEST STREET DAINEW YORK CITY DAJSC DAK10005
DARD
DAS
DAT
DAU601 DAW170 DAYBRO
DAZBRO
DBA20241004 DBB19911004 DBC1 DBD20140101 DBG2 DBH1

2

There are 2 best solutions below

0
On

You can use LEADTOOLS Forms SDK technology in your application. https://www.leadtools.com/sdk/ocr/forms/recognition-processing You can leverage the BarcodeEngine and AAMVAID classes, which will allow you to recognize the PDF417 AAMVA barcode and extract the encoded information. Do note that I am an employee of this toolkit.

DISCLOSURE: I am an employee of the company offering this toolkit.

Here is some sample code:

using (RasterCodecs _codecs = new RasterCodecs())
using (RasterImage _image = _codecs.Load(@"C:\LEADTOOLS21\Resources\Images\license_sample_rear_aamva.png"))
{
    // Create the BarcodeEngine
    BarcodeEngine _bcEngine = new BarcodeEngine();
    BarcodeData _data = _bcEngine.Reader.ReadBarcode(_image, LeadRect.Empty, BarcodeSymbology.PDF417);
    if (_data.Value != null && _data.Symbology == BarcodeSymbology.PDF417)
    {
        AAMVAID _id = BarcodeData.ParseAAMVAData(_data.GetData(), false);
        if (_id != null)
        {
            Console.WriteLine("AAMVA PDF417 Barcode Found!\n" + 
                  "==============================================="); 
            Console.WriteLine($"Issuer Identification Number: {_id.IssuerIdentificationNumber}\n" + 
                  $"First Name: {_id.FirstName.Value}\n" + 
                  $"Last Name: {_id.LastName.Value}\n" + 
                  $"Over 21? {_id.Over21}\n");
            // Note: There are many more properties in the AAMVAID class to gather data. 
        }
        else
        {
            Console.WriteLine("Does not meet AAMVA specifications");   
        }
    }
    else
    {
        Console.WriteLine("PDF417 Barcode Not Found!");
    }
}

I tried the barcode in your image and this is what I received.

AAMVA Extraction Result

0
On

Most of the 50 U.S. states follow the AAMVA DL/ID standards https://www.aamva.org/topics/driver-license-and-identification-standards?#?wst=4a3b89462cc2cff2cbe0c7accde57421/. Go to the website and scroll down to AAMVA DL/ID Card Design Standard (2020) and download the PDF. Annex D explains all of the data elements inside the barcode contents. According to this document, the driver's license starts after its element DAQ. So in your example, the driver's license is 3265188 which appears after DAQ and before the next element, DAA, starts.