Extract Driver's License AAMVA Barcode - Console C#

This tutorial shows how to create a C# Windows Console application that utilizes data extraction from a PDF417 barcode that follows the AAMVA specification using the LEADTOOLS SDK.

Overview  
Summary This tutorial covers how to use LEADTOOLS AAMVA PDF417 SDK technology in a C# Windows Console application.
Completion Time 30 minutes
Visual Studio Project Download tutorial project (3 KB)
Platform Windows Console C# Application
IDE Visual Studio 2017, 2019
Development License Download LEADTOOLS
Try it in another language

Required Knowledge

Before working on the Extract Driver's License AAMVA Barcode - Console C# tutorial, get familiar with the basic steps of creating a project by reviewing the Add References and Set a License tutorial.

Create the Project and Add LEADTOOLS References

Start with a copy of the project created in the Load and Save Images tutorial. If you don't have that project, follow the steps in that tutorial to create it.

If using NuGet references, this tutorial requires the following NuGet package:

If local DLL references are used, the following DLLs are needed. The DLLs are located at <INSTALL_DIR>\LEADTOOLS21\Bin\Dotnet4\x64:

For a complete list of which Codec DLLs are required for specific formats, refer to File Format Support.

Set the License File

The License unlocks the features needed for the project. It must be set before any toolkit function is called. For details, including tutorials for different platforms, refer to Setting a Runtime License.

There are two types of runtime licenses:

Note

Adding LEADTOOLS NuGet and local references and setting a license are covered in more detail in the Add References and Set a License tutorial.

Add the AAMVA PDF417 Extraction Code

Ensure that all of the necessary set license and loading code are added into the Windows Console C# application as covered in the Add References and Set a License and the Load and Save Images tutorials. Saving the image is not necessary in this tutorial, so comment out the according code.

With the project created, the references added, and the license set, coding can begin.

In the Solution Explorer, open Program.cs. Add the following statements to the using block at the top.

C#
// Using block at the top 
using System; 
using System.IO; 
using Leadtools; 
using Leadtools.Barcode; 
using Leadtools.Codecs; 

Add a new method called ExtractPDF417Data(RasterImage image) and then call the new method in the Main method. Add the below PDF417 AAMVA extraction code inside the new method. The method's parameter will be the RasterImage loaded in RasterImage image = LoadImage(@"C:\LEADTOOLS21\Resources\Images\license_sample_rear_aamva.png");. For this tutorial use this AAMVA PDF417 sample image.

C#
static void Main(string[] args) 
{ 
    SetLicense(); 
    RasterImage image = LoadImage(@"C:\LEADTOOLS21\Resources\Images\license_sample_rear_aamva.png"); 
    ExtractPDF417Data(image); 
    //SaveImage(image, @"C:\Temp\output.jpg"); 
 
    Console.WriteLine("Press any key to exit..."); 
    Console.ReadKey(); 
} 
C#
static void ExtractPDF417Data(RasterImage image) 
{ 
    // Create a Barcode engine  
    BarcodeEngine engine = new BarcodeEngine(); 
    BarcodeData data = engine.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"); 
        } 
        else 
        { 
           Console.WriteLine("Does not meet AAMVA specifications"); 
        } 
    } 
    else 
    { 
        Console.WriteLine("PDF417 Barcode Not Found!"); 
    } 
} 

Note

There are more properties inside the AAMVAID class, the snippet above showcases a few commonly used properties.

Run the Project

Run the project by pressing F5, or by selecting Debug -> Start Debugging.

If the steps were followed correctly, the application runs and displays the data inside the PDF417 Barcode.

Extracted PDF417 Barcode

Wrap-Up

This tutorial showed how to use the BarcodeData and AAMVAID classes.

See Also

Help Version 21.0.2023.3.1
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2021 LEAD Technologies, Inc. All Rights Reserved.


Products | Support | Contact Us | Intellectual Property Notices
© 1991-2021 LEAD Technologies, Inc. All Rights Reserved.