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 |
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.
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
leadtools.jar
leadtools.barcode.jar
leadtools.codecs.jar
For a complete list of which JAR files are required for your application, refer to Files to be Included with your Java Application
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.
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.
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.
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.
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 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.
This tutorial uses this sample image
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.