Extract Driver's License AAMVA Barcode - .NET Core

This tutorial shows how to create a C# .NET Core 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# .NET Core Console application.
Completion Time 30 minutes
Visual Studio Project Download tutorial project (1 KB)
Platform C# .NET Core 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 - .NET Core tutorial, get familiar with the basic steps of creating a project by reviewing the Add References and Set a License and Load and Save Images tutorials. Saving the image is not necessary in this tutorial, so comment out or remove the saving code.

Create the Project and Add the LEADTOOLS References

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

This tutorial requires the following NuGet packages:

For a complete list of which DLLs are required for specific barcode features, refer to Barcode 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

How to properly add LEADTOOLS NuGet references is covered in the Add References and Set a License tutorial.

Add the AAMVA PDF417 Extraction Code

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

In the Solution Explorer, open Program.cs and add the following statements to the using block at the top of Program.cs:

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

Add a new method called ExtractPDF417Data(RasterImage image). Call the new method in the Main method below the LoadImage(@"C:\LEADTOOLS22\Resources\Images\license_sample_rear_aamva.png") method.

C#
static void Main(string[] args) 
{ 
   if (!SetLicense()) 
   { 
      Console.WriteLine("Error setting license"); 
      return; 
   } 
   RasterImage image = LoadImage(@"C:\LEADTOOLS22\Resources\Images\license_sample_rear_aamva.png"); 
   ExtractPDF417Data(image); 
   Console.WriteLine("Press any key to exit..."); 
   Console.ReadKey(true); 
} 

The method's parameter will be the RasterImage loaded in the LoadImage() method. This tutorial uses this AAMVA PDF417 sample image. Add the below PDF417 AAMVA extraction code inside the new method.

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 data displayed to the console.

Wrap-Up

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

See Also

Help Version 22.0.2021.10.18
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.