Decode US Driver License PDF417 Barcodes with Java

Call a deterministic PDF417 and AAMVA API from Java, return structured identity fields, and reject unreadable barcodes without AI guessing.

Why US Driver License PDF417 Decoding Needs a Dedicated Pipeline

The barcode on the back of a US driver license is not ordinary printed text. PDF417 uses stacked rows, error correction, and a structured AAMVA payload. Glare, blur, perspective, small barcodes, and partial cropping can prevent a reliable decode. General OCR and generative vision models may produce plausible-looking identity fields, but they cannot prove those values came from a valid barcode payload.

A Deterministic PDF417 API for Java

Send a JPG, PNG, or WebP image to the US driver license PDF417 API. StructOCR locates and decodes the barcode, validates the result, parses AAMVA elements, and returns normalized JSON. Try the workflow first in the free PDF417 scanner.

Production Use Cases

  • US Customer Onboarding: Pre-fill identity and address fields from an AAMVA-compliant license-back barcode.
  • Rental and Fleet Intake: Capture license number, class, restrictions, endorsements, and expiration date.
  • Quality-Control Queues: Route 422 responses to a retake flow instead of accepting guessed identity data.
Need more testing? Create a free account to get 200 free credits (equals 100 Driver License scans).

Implementation: Java REST Request

Read the license-back image, Base64 encode it, send it with the x-api-key header, and treat HTTP 422 as a request for a clearer image.

Prerequisite: Java 17+ and Jackson Databind

JAVA EXAMPLE
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.net.URI;
import java.net.http.*;
import java.nio.file.Files;
import java.nio.file.Path;
import java.time.Duration;
import java.util.Base64;
import java.util.Map;

ObjectMapper mapper = new ObjectMapper();
String image = Base64.getEncoder().encodeToString(
    Files.readAllBytes(Path.of("license-back.jpg"))
);
String body = mapper.writeValueAsString(Map.of("img", image));

HttpRequest request = HttpRequest.newBuilder()
    .uri(URI.create("https://api.structocr.com/v1/driver-license-pdf417"))
    .timeout(Duration.ofSeconds(30))
    .header("Content-Type", "application/json")
    .header("x-api-key", System.getenv("STRUCTOCR_API_KEY"))
    .POST(HttpRequest.BodyPublishers.ofString(body))
    .build();

HttpResponse<String> response = HttpClient.newHttpClient()
    .send(request, HttpResponse.BodyHandlers.ofString());
JsonNode result = mapper.readTree(response.body());

if (response.statusCode() == 422) {
    System.out.println("Retake image: " + result.path("error").asText());
} else if (response.statusCode() != 200) {
    throw new RuntimeException(response.body());
} else {
    JsonNode data = result.path("data");
    System.out.println("License: " + data.path("document_number").asText());
    System.out.println("DOB: " + data.path("date_of_birth").asText());
}

Technical Specs

  • •Endpoint: POST https://api.structocr.com/v1/driver-license-pdf417
  • •Authentication: x-api-key request header
  • •Inputs: JPG, PNG, or WebP; Base64 JSON or multipart upload
  • •Maximum file size: 4.5MB
  • •Price: 2 credits for a successful decode; processing failures are refunded
  • •Output: Structured AAMVA JSON; raw barcode payload is not returned

Key Features

  • •No AI guessing: Identity fields come from a decoded PDF417 payload and AAMVA parser.
  • •Explicit retake flow: Handle PDF417_NOT_DECODED as a 422 response and ask for a clear, glare-free image.
  • •AAMVA validation: AAMVA_NOT_VALID distinguishes a readable non-license barcode from a usable driver-license record.
  • •Normalized dates: Birth, issue, and expiration dates use YYYY-MM-DD when available.

Sample AAMVA JSON Output

The example uses fictional values. Optional AAMVA elements return null when absent.

{
  "success": true,
  "data": {
    "type": "drivers_license",
    "source": "pdf417",
    "country_code": "USA",
    "region": "CA",
    "document_number": "SAMPLE1234",
    "surname": "SAMPLE",
    "given_names": "ALEX MORGAN",
    "first_name": "ALEX",
    "middle_name": "MORGAN",
    "sex": "F",
    "date_of_birth": "1990-01-15",
    "date_of_issue": "2025-01-15",
    "date_of_expiry": "2030-01-15",
    "address": "100 EXAMPLE AVE",
    "city": "SAMPLE CITY",
    "postal_code": "90001",
    "vehicle_class": "C",
    "restrictions": "NONE",
    "endorsements": "NONE",
    "document_discriminator": "SAMPLE-DISCRIMINATOR",
    "issuer_identification_number": "636000",
    "aamva_version": 10,
    "jurisdiction_version": 0
  }
}

Frequently Asked Questions

Can Java decode a PDF417 barcode without a local barcode library?

Yes. Your application only needs to send the image to the REST endpoint and parse JSON. PDF417 decoding and AAMVA parsing run in the StructOCR service.

What should my application do with PDF417_NOT_DECODED?

Treat HTTP 422 as a recoverable capture problem. Ask the user to retake the back of the license with the full barcode visible, sharp, and free from glare. Processing failures are refunded.

Is this the same as front-side driver license OCR?

No. This endpoint is dedicated to PDF417 barcodes on the back of US driver licenses and State IDs. Use the Driver License OCR API for visible printed fields and international license formats.

You May Also Like

Related tutorials, platform guides, and comparisons

Tutorial

Java Driver License OCR API

Upload an image for a free test! High-accuracy Java Driver's License OCR API. Get structured JSON output from images via a simple HTTP request. Eliminate manual entry & Tesseract errors.

Java · Driver License
Country Tutorial

US Driver License OCR with Python SDK

Extract structured fields from a United States state-issued driver license with the StructOCR Python SDK and FastAPI.

Python · Driver License
Country Tutorial

Maryland Driver License OCR: Extract Fields with Python

Extract visible fields from Maryland driver license images into JSON. Map identifiers, names and dates, with a review workflow for incomplete results.

Python · Driver License
Country Tutorial

Louisiana Driver License OCR: Extract Fields with Python

Extract visible fields from Louisiana driver license images into JSON. Map identifiers, names and dates, with a review workflow for incomplete results.

Python · Driver License
Tutorial

Python US Driver License PDF417 API Tutorial

Decode US driver license PDF417 barcodes with Python. Send a license-back image, parse AAMVA fields, and handle unreadable barcode errors safely.

Python · Driver License
Country Tutorial

US Driver License OCR with Node.js SDK

Extract structured fields from a United States state-issued driver license with the StructOCR Node.js SDK and TypeScript + Express.

Node.js · Driver License
Country Tutorial

UK Driver License OCR with Python SDK

Extract structured fields from a United Kingdom photocard driving licence with the StructOCR Python SDK and FastAPI.

Python · Driver License
Tutorial

Node.js Driver License Verification API

Stop manual driver license checks. Our Node.js API delivers verified data in JSON within <4s, secured by AES-256 encryption and SOC2 compliance. Upload an image for a free test!

Node.js · Driver License
Country Tutorial

UK Driver License OCR with Node.js SDK

Extract structured fields from a United Kingdom photocard driving licence with the StructOCR Node.js SDK and TypeScript + Express.

Node.js · Driver License
Tutorial

Java Vehicle Registration OCR API

Java Vehicle Registration OCR API tutorial. Upload an image for a free test! Accurately extract standardized fields like VIN, make, and model, along with dynamically localized data for global documents.

Java · Vehicle Reg.

Technical Comparisons & Integrations

Explore platform integrations and competitive analysis

From tutorial to production in 5 minutes.

You've seen the code. Now get your API key, grab your 200 free credits, and see it work with your own images. No credit card required.

Instant Access Cancel Anytime No Credit Card