Extract Drivers License AAMVA Barcode - Java

This tutorial shows how to perform data extraction from a PDF417 barcode that follows the AAMVA specification in a Java application using the LEADTOOLS SDK.

Overview
Summary This tutorial covers how to perform data extraction from a PDF417 that follows the AAMVA specification 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

Start with a copy of the project created in the Load and Save an Image tutorial. If that project is unavailable, follow the steps in that tutorial to create it.

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>\LEADTOOLS22\Bin\Java

For a complete list of which JAR files are required for your application, refer to Files to be Included with your Java Application

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 run() method after the SetLicense() call.

Java
public static void main(String[] args) throws IOException 
{ 
	new _Main().run(args); 
} 
private void run(String[] args) { 
	try { 
		Platform.setLibPath("C:\\LEADTOOLS22\\Bin\\CDLL\\x64"); 
		Platform.loadLibrary(LTLibrary.LEADTOOLS); 
		Platform.loadLibrary(LTLibrary.BARCODE); 
		Platform.loadLibrary(LTLibrary.CODECS); 
			 
		SetLicense(); 
			 
		RasterCodecs codecs = new RasterCodecs(); 
		String inputFile = "C:\\LEADTOOLS22\\Resources\\Images\\license_sample_rear_aamva.png"; 
		RasterImage image = LoadImage(inputFile, codecs); 
		ExtractPDF417Data(image); 
	}  
	catch(Exception ex) { 
		System.err.println(ex.getMessage()); 
		ex.printStackTrace(); 
	} 
} 

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

Java
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 22.0.2024.3.20
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.

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