Invoice Data Extraction API for Java: Raw Power, No SDK Required
Achieve 99.2%+ accuracy on line item and table extraction in under 1500ms via a single API call.

Why Invoice OCR Fails with Generic Tools
Standard OCR engines like Tesseract fail on invoices because they are not documents of a fixed structure; they are semi-structured at best. Layouts vary wildly between vendors, making template-based RegEx solutions brittle and high-maintenance. Accurately parsing tables with multi-line descriptions, variable columns, and calculating line item totals is non-trivial. Real-world challenges like low-resolution scans, JPEG compression artifacts, skew, and shadows further degrade accuracy. This forces engineering teams into a perpetual cycle of building and maintaining complex pre-processing pipelines and post-processing validation rules, distracting from core product development and still resulting in costly manual data entry.
Enterprise-Grade Extraction with StructOCR
StructOCR replaces this entire fragile stack with a single API endpoint. Our service is powered by pre-trained deep learning models specifically designed for invoice and receipt layouts. Upon receiving an image, our pipeline automatically performs pre-processing, including deskewing, denoising, and contrast correction. The model then identifies and extracts key-value pairs, line items, and tabular data, contextualizing the information rather than performing a raw text dump like Tesseract. The output is a predictable, standardized JSON schema, eliminating the need for custom parsing logic and delivering data ready for direct integration into your Accounts Payable systems.
Production Use Cases
- Automated Accounts Payable: Ingest vendor invoices from any source (email, scan, photo) and automatically populate your ERP or accounting software, eliminating manual data entry errors.
- Expense Management Automation: Enable real-time expense reporting by allowing users to simply photograph receipts and invoices, with line-item level data extracted instantly.
- Three-Way Matching: Drastically reduce invoice processing time by programmatically matching extracted data against purchase orders and goods receipt notes with over 99% accuracy.
Implementation: Java (Standard HttpClient)
The following Java code uses the native `java.net.http.HttpClient` (Java 11+). It demonstrates how to construct the JSON payload manually and handle the `x-api-key` header without external dependencies.
Prerequisite: JDK 11+
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;
public class InvoiceOcrExample {
// 💰 Save 30%+ vs competitors. Get 200 free requests 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/invoice";
public static void main(String[] args) {
// Note: Currently supports image inputs (JPG, PNG)
String imagePath = "invoice.jpg";
try {
// 1. Validate File
Path path = Path.of(imagePath);
if (!Files.exists(path)) {
System.err.println("Error: File not found at " + path.toAbsolutePath());
return;
}
// 2. Read image and encode to Base64
byte[] imageBytes = Files.readAllBytes(path);
String base64Image = Base64.getEncoder().encodeToString(imageBytes);
// 3. Construct JSON Payload (Dependency-free)
// Ideally, use a library like Jackson or Gson for production.
String jsonPayload = "{\"img\": \"" + base64Image + "\"}";
// 4. Create HttpClient
HttpClient client = HttpClient.newBuilder()
.version(HttpClient.Version.HTTP_1_1)
.connectTimeout(Duration.ofSeconds(10))
.build();
// 5. Build Request
// Important: 'x-api-key' header is required
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create(API_ENDPOINT))
.header("Content-Type", "application/json")
.header("x-api-key", API_KEY)
.timeout(Duration.ofSeconds(30))
.POST(HttpRequest.BodyPublishers.ofString(jsonPayload))
.build();
System.out.println("Sending invoice to " + API_ENDPOINT + "...");
// 6. Send Request
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
// 7. Output Result
if (response.statusCode() == 200) {
System.out.println("✅ Extraction Successful!");
// The response contains nested JSON: merchant, financials, line_items
System.out.println("Response Body:");
System.out.println(response.body());
} else {
System.err.println("❌ API Error: " + response.statusCode());
System.err.println(response.body());
}
} catch (IOException | InterruptedException e) {
System.err.println("Request failed: " + e.getMessage());
Thread.currentThread().interrupt();
}
}
}Technical Specs
- •Latency: < 5s (Average)
- •Uptime: 98.5% SLA
- •Security: AES-256 Encryption & SOC2 Compliant
- •Input: JPG, PNG, WebP (Base64 Encoded)
- •Max File Size: 4.5MB
- •Output: JSON (Nested Structure)
Key Features
- •Table Extraction Engine: Accurately parses complex line items and tables without manual templating.
- •Financial Validation: Cross-validates subtotals, taxes, and grand totals to ensure mathematical accuracy.
- •Vendor Normalization: Automatically identifies merchants and extracts standardized tax IDs (VAT/EIN).
Sample JSON Output
StructOCR returns a normalized JSON object, regardless of the input image angle or quality.
{
"success": true,
"data": {
"type": "invoice",
"invoice_number": "INV-2026-001",
"date": "2026-01-15",
"due_date": "2026-02-15",
"currency": "USD",
"merchant": {
"name": "AWS Web Services",
"address": "410 Terry Ave N, Seattle, WA",
"tax_id": "EIN-12-3456789",
"iban": null
},
"customer": {
"name": "Acme Corp Inc.",
"tax_id": "987654321"
},
"financials": {
"subtotal": 100,
"tax_amount": 10,
"total_amount": 110
},
"line_items": [
{
"description": "EC2 Instance Usage",
"quantity": 1,
"unit_price": 80,
"amount": 80
},
{
"description": "S3 Storage",
"quantity": 1,
"unit_price": 20,
"amount": 20
}
]
}
}Frequently Asked Questions
How does StructOCR compare to AWS Textract or Google Vision?
While generic services like Textract and Vision provide raw text blocks and coordinates, StructOCR is a specialized, pre-trained model for invoices. It returns a structured JSON with explicitly defined fields like `invoice_number`, `due_date`, and a parsed array of `line_items`. This eliminates the need for you to build and maintain a complex post-processing layer to make sense of the raw OCR data.
Do you store the uploaded images?
No. Images and data are processed in-memory and permanently deleted immediately after the transaction is complete. We do not persist customer data.
How do you handle low-quality or blurry images?
Our API includes an internal image pre-processing engine that automatically handles common issues like low resolution, blur, and poor lighting to maximize extraction accuracy before the data is passed to the core model.
More OCR Tutorials
Java Driver's License OCR API
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 National ID OCR API
Reliable Java API for National ID OCR. Achieve 99.8%+ accuracy for KYC automation. Get structured JSON output from any ID image. High Accuracy guaranteed.
Java Passport OCR API
Achieve 99%+ accuracy for Passport MRZ and VIZ data extraction in Java. Our API provides structured JSON output, handling glare and blur automatically.
Java VIN (Vehicle Identification Number) OCR API
Tutorial: How to use the StructOCR Java Client to extract data from VIN (Vehicle Identification Number)s. Includes code samples and JSON schema.
Precise Data Extraction and Seamless
Integration with AI-powered OCR API.
Empower your solutions with automated data extraction by
integrating best-in class StructOCR via API seamlessly.
No credit card required • Full API access included