Extract Drivers License AAMVA Barcode - Java

This tutorial shows how to use the LEADTOOLS SDK to create a Java application that extracts the data from a PDF417 barcode that follows the AAMVA specification.

Overview
Summary This tutorial covers how to run AAMVA barcode extraction in a Java application.
Completion Time 30 minutes
Project Download tutorial project (1 KB)
Platform Java Application
IDE Eclipse
Runtime License Download LEADTOOLS

Required Knowledge

Get familiar with the basic steps of creating a project by reviewing the Add References and Set a License and Load and Save an Image tutorials, before working on the Extract Drivers License AAMVA Barcode - Java tutorial.

Saving images is not necessary to this tutorial, so saving portion can be commented out.

Create the Project and Add LEADTOOLS References

In Eclipse, create a new Java project, and add the necessary LEADTOOLS references.

The references needed depend upon the purpose of the project. The following JAR files are needed for this tutorial:

The JAR files are located at <INSTALL_DIR>\LEADTOOLS21\Bin\Java

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 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

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

In the Package Explorer, open the _Main.java class. Add the following import statements to the import block at the top.

Java
import java.io.IOException; 
import java.nio.file.Files; 
import java.nio.file.Paths; 
 
import leadtools.*; 
import leadtools.barcode.*; 
import leadtools.codecs.*; 

Add a new method to the _Main class called ExtractPDF417Data(RasterImage image). Call this method inside the main() method after the SetLicense() call.

Java
public static void main(String[] args) throws IOException 
{ 
	Platform.setLibPath("C:\\LEADTOOLS21\\Bin\\CDLL\\x64"); 
	Platform.loadLibrary(LTLibrary.LEADTOOLS); 
	Platform.loadLibrary(LTLibrary.BARCODE); 
	Platform.loadLibrary(LTLibrary.CODECS); 
		 
	SetLicense(); 
		 
	RasterCodecs codecs = new RasterCodecs(); 
	String inputFile = "C:\\LEADTOOLS21\\Resources\\Images\\license_sample_rear_aamva.png"; 
	RasterImage image = LoadImage(inputFile, codecs); 
	ExtractPDF417Data(image); 
} 

Add the below code to extract the data from an AAMVA standard PDF417 barcode.

Java
static void ExtractPDF417Data(RasterImage image) 
{ 
	BarcodeEngine engine = new BarcodeEngine(); 
	BarcodeData data = engine.getReader().readBarcode(image, LeadRect.getEmpty(), BarcodeSymbology.PDF417); 
	if(data.getValue() != null) 
	{ 
		AAMVAID id = BarcodeData.parseAAMVAData(data.getData(), false); 
		if (id != null) 
		{ 
			System.out.println("AAMVA PDF417 Barcode Found!\n" + 
	                                "==============================================="); 
			System.out.println("Issuer Identification Number: " + id.getIssuerIdentificationNumber() +  
						            "\nFirst Name: " + id.getFirstName().getValue() +  
						            "\nLast Name: " + id.getLastName().getValue() +  
						            "\nOver 21? " + id.isOver21()); 
		} 
		else 
		{ 
			System.out.println("Does not meet AAMVA specifications"); 
		} 
	} 
	else 
    { 
		System.out.println("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 selecting Run -> Run.

If the steps were followed correctly, the application loads the PNG image of the back of the driver's license sample, runs barcode recognition, and outputs the AAMVA barcode data.

Java console output display screenshot

This tutorial uses this sample image

Wrap-up

This tutorial showed how to extract data from a driver's license PDF417 barcode. Also, it covered how to use the BarcodeEngine, BarcodeData, and AAMVAID classes.

See Also

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