Java Driver's License OCR via a Simple REST API
Achieve 99.7%+ accuracy and sub-second latency for driver's license data extraction, directly into your Java application.

Why Driver's License OCR is Difficult
Accurate driver's license OCR is a non-trivial engineering challenge. Standard libraries like Tesseract fail on real-world inputs due to variable lighting, glare, shadows, and image skew. Parsing the PDF417 barcode requires specialized libraries that often fail on minor data corruption or non-standard encoding. Beyond the image, extracting specific fields requires maintaining complex, brittle RegEx patterns for over 200+ AAMVA jurisdiction formats, a significant maintenance burden. Calculating MRZ checksums for validation adds another layer of complexity. An in-house solution requires constant updates to handle new license designs, leading to high operational costs and inconsistent accuracy.
Enterprise-Grade Extraction with StructOCR
StructOCR simplifies identity document processing with a single API call. Our service leverages pre-trained deep learning models optimized for drivers license ocr, surpassing generalized OCR solutions. The API pipeline incorporates automatic image pre-processing—deskewing, denoising, and glare correction—ensuring high accuracy even with low-quality mobile captures. We internally manage PDF417 parsing and field extraction for documents like driving permits, returning a clean, standardized JSON object. This eliminates manual parsing and Regex maintenance, providing predictable, structured data for immediate integration.
Production Use Cases
- Digital Onboarding (KYC): Reduce drop-off rates by pre-filling user data from Driver's Licenses in < 2 seconds.
- Fraud Prevention: Detect tampered fonts or mismatched MRZ checksums automatically.
- Global Compliance: Handle Driver's Licenses from 200+ jurisdictions without custom rules.
Live Demo: Driver License OCR Scanner
No registration required. Upload a file to test the extraction.
Drop files here or click to browse
JPG · PNG · WebP · up to 500 files · max 4.5 MB each
Implementation: Java (HttpClient + Jackson)
This example uses the native `java.net.http.HttpClient` introduced in Java 11 for the network request, and the popular `Jackson` library to parse the advanced nested JSON fields like the Document Discriminator (DD).
Prerequisite: JDK 11+ and Jackson Databind
import java.io.IOException;
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.nio.file.Files;
import java.nio.file.Path;
import java.time.Duration;
import java.util.Base64;
// Requires Jackson: com.fasterxml.jackson.core:jackson-databind
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
public class StructOcrApiExample {
// 💰 Save 30%+ vs competitors. Get 200 free credits instantly:
// 👉 https://structocr.com/register
private static final String API_KEY = "YOUR_API_KEY_HERE";
private static final String API_ENDPOINT = "https://api.structocr.com/v1/driver-license";
public static void main(String[] args) {
String imagePath = "license.jpg";
try {
// 1. Read image file and encode to Base64
Path path = Path.of(imagePath);
if (!Files.exists(path)) {
System.err.println("Error: File not found at " + path.toAbsolutePath());
return;
}
byte[] imageBytes = Files.readAllBytes(path);
String base64Image = Base64.getEncoder().encodeToString(imageBytes);
// 2. Construct JSON Payload manually for simplicity
String jsonPayload = "{\"img\": \"" + base64Image + "\"}";
// 3. Create HttpClient (Java 11+)
HttpClient client = HttpClient.newBuilder()
.connectTimeout(Duration.ofSeconds(10))
.build();
// 4. Build Request
// Important: 'x-api-key' is required in the header
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create(API_ENDPOINT))
.header("Content-Type", "application/json")
.header("x-api-key", API_KEY)
.POST(HttpRequest.BodyPublishers.ofString(jsonPayload))
.build();
System.out.println("Sending request to " + API_ENDPOINT + "...");
// 5. Send Request
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
// 6. Output Result using Jackson
if (response.statusCode() == 200) {
ObjectMapper mapper = new ObjectMapper();
JsonNode root = mapper.readTree(response.body());
JsonNode data = root.path("data");
System.out.println("✅ Extraction Successful!");
System.out.println("Name: " + data.path("given_names").asText() + " " + data.path("surname").asText());
System.out.println("Doc Number: " + data.path("document_number").asText());
System.out.println("Vehicle Class: " + data.path("vehicle_class").asText());
// Highlighting the advanced security feature extraction
JsonNode extraDetails = data.path("extra_details");
if (!extraDetails.isMissingNode() && !extraDetails.path("card_security_number").isNull()) {
System.out.println("Security Code (DD): " + extraDetails.path("card_security_number").asText());
}
} else {
System.err.println("❌ API Error: " + response.statusCode());
System.err.println(response.body());
}
} catch (Exception e) {
e.printStackTrace();
}
}
}Technical Specs
- •Latency: < 4s (Average)
- •Uptime: 99.9% SLA
- •Security: AES-256 Encryption & SOC2 Compliant
- •Input: JPG, PNG, WebP (Base64 Encoded)
- •Max File Size: 4.5MB
- •Output: JSON (Structured Data)
Key Features
- •True Global Compatibility: Out-of-the-box support for North American AAMVA standards, EU numbered fields, and complex LATAM layouts (e.g., Brazil CNH) without maintaining custom RegEx.
- •Date Normalization: All dates automatically formatted to YYYY-MM-DD.
- •Vehicle Class Parsing: Extracts allowed vehicle categories (e.g., A, B, C).
Sample JSON Output
StructOCR returns a normalized JSON object, regardless of the input image angle or quality.
{
"success": true,
"data": {
"type": "drivers_license",
"country_code": "USA",
"region": "CA",
"document_number": "E3802489",
"personal_number": null,
"surname": "IDNOOB",
"given_names": "MING",
"address": "750 GONZALEZ DR APT 6B, SAN FRANCISCO, CA 94512",
"vehicle_class": "C",
"sex": "F",
"date_of_birth": "1988-06-06",
"date_of_expiry": "2020-06-06",
"date_of_issue": "2015-07-22",
"extra_details": {
"card_security_number": "06/09/2014599A5/DOFD/19",
"fathers_name": null,
"mothers_name": null,
"rg_number": null
}
}
}Frequently Asked Questions
How does StructOCR compare to AWS Textract or Google Vision?
General-purpose OCR services like AWS Textract or Google Vision return raw, unstructured text lines, requiring you to build and maintain complex parsers. StructOCR is a specialized, pre-trained model for identity documents. It directly returns a structured JSON with validated fields like `surname`, `date_of_birth`, and `document_number`, eliminating the post-processing development effort.
Do you store the uploaded images?
No. We operate on a zero-retention policy for customer data. Images are processed in-memory and are purged immediately after the OCR process completes. We do not store or log any uploaded image data.
How do you handle blurry or low-quality images?
Our API includes a built-in image enhancement engine that automatically attempts to correct for issues like motion blur, poor focus, and low contrast before the OCR process begins. This significantly increases the success rate for images captured by users in suboptimal conditions.
You May Also Like
Related tutorials, platform guides, and comparisons
UK Driver License OCR with Python SDK
Extract structured fields from a United Kingdom photocard driving licence with the StructOCR Python SDK and FastAPI.
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.
Python Driver License OCR SDK & API
Stop struggling with manual data entry. Integrate our driver license OCR SDK (Python wrapper) to extract structured JSON in <3s. Upload an image for a free test! Secure, accurate, and developer-friendly.
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.
Philippines Driver License OCR with Python SDK
Extract structured fields from a Philippines LTO driver's license with the StructOCR Python SDK and FastAPI.
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.
Go Driver License OCR API
Upload an image for a free test! Struggling with manual driver's license data entry? Our Go API delivers structured JSON in <5s, boasting 98.5% uptime and SOC2 compliance with AES-256 encryption.
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. Achieve 98.5% uptime. Upload an image for a free test!
Australia Driver License OCR with Node.js SDK
Extract structured fields from a Australia state or territory driver licence with the StructOCR Node.js SDK and TypeScript + Express.
Australia Driver License OCR with Python SDK
Extract structured fields from a Australia state or territory driver licence with the StructOCR Python SDK and FastAPI.
Technical Comparisons & Integrations
Explore platform integrations and competitive analysis
Add Driver's License OCR to Your Bolt.new App in 5 Minutes
Step-by-step guide to integrating the StructOCR Driver's License scanner API into a Bolt.new app. Build car rental and mobility onboarding flows right in your browser.
Add Driver's License OCR using Cursor in 5 Minutes
Step-by-step guide to integrating the StructOCR Driver's License scanner API using the Cursor AI code editor. Build car rental and mobility onboarding flows rapidly.
Add Driver's License OCR to Your Lovable.dev App in 5 Minutes
Step-by-step guide to integrating the StructOCR Driver's License scanner API into a Lovable.dev app. Build car rental and mobility onboarding flows with zero backend.
Add Driver's License OCR to Your Replit App in 5 Minutes
Step-by-step guide to integrating the StructOCR Driver's License scanner API into a Replit application. Build car rental and mobility onboarding flows using Replit Agent and Secrets.
Add Driver's License OCR to Your v0 App in 5 Minutes
Step-by-step guide to integrating the StructOCR Driver's License scanner API into a v0 by Vercel app. Build car rental and mobility onboarding flows with zero backend.
Add VIN OCR to Your v0 App in 5 Minutes
Step-by-step guide to integrating the StructOCR VIN scanner API into a v0 by Vercel app. Build automotive and fleet tools with zero backend.
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.