Java OCR Invoice API: Enterprise Data Extraction
Achieve 99.7%+ accuracy in under 3 second. Upload your invoice below to see real-time JSON extraction in action, or integrate via our REST API.

Why Invoice OCR Fails with Generic Tools
Standard OCR engines like Tesseract fail on invoices because they are not documents of a fixed structure. 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, PDF artifacts, skew, and shadows further degrade accuracy. This forces engineering teams into a perpetual cycle of building complex post-processing validation rules, distracting from core product development.
Enterprise-Grade Extraction with StructOCR
StructOCR replaces this entire fragile stack with a single API endpoint. Powered by pre-trained deep learning models, our Java OCR invoice engine automatically performs deskewing and denoising on edge servers before analysis. The model extracts key-value pairs, line items, and tabular data, outputting a predictable JSON schema rather than a raw text dump. This eliminates custom parsing logic and delivers data ready for direct accounts payable automation in your ERP systems. For full endpoint details and official wrappers (including Java and Node.js SDKs), visit our developer documentation.
Production Use Cases
- Automated Accounts Payable: Ingest vendor invoices from any source (email PDFs, scans, photos) and automatically populate your ERP, eliminating manual data entry errors.
- Expense Management Automation: Enable real-time expense reporting by allowing users to simply upload 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.
Live Demo: Invoice extractor
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
Ready to use this in production? Get 20 free API calls — no credit card needed.
Get 20 Free API Calls →Implementation: Java (Standard HttpClient)
The following Java code uses the native `java.net.http.HttpClient` (Java 11+). It demonstrates how to encode an invoice PDF to Base64 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 20 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/invoice";
public static void main(String[] args) {
// Supports PDFs, local image paths, Base64 strings, or Image URLs
String documentPath = "vendor_invoice.pdf";
try {
// 1. Validate File
Path path = Path.of(documentPath);
if (!Files.exists(path)) {
System.err.println("Error: File not found at " + path.toAbsolutePath());
return;
}
// 2. Read document and encode to Base64
byte[] fileBytes = Files.readAllBytes(path);
String base64Data = Base64.getEncoder().encodeToString(fileBytes);
// 3. Construct JSON Payload (Dependency-free)
// Ideally, use a library like Jackson or Gson for production.
String jsonPayload = "{\"img\": \"" + base64Data + "\"}";
// 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
- •Infrastructure: Distributed Global Edge Network
- •Latency: < 1s (Average response time)
- •Security: AES-256 Encryption, In-memory processing (Zero data retention)
- •Inputs Supported: PDF, File Upload (JPG/PNG/WebP), Base64 String, Image URL
- •Output: Structured JSON
Key Features
- •Table Extraction Engine: Accurately parses complex line items across multi-page PDFs 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).
- •Flexible Payloads: Pass Base64 data directly from Java clients to bypass intermediate local storage.
Sample JSON Output
The API returns a normalized JSON object, regardless of whether the input is a scanned image or a digital PDF.
{
"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 or PDFs?
No. Images and documents are processed in-memory on our edge servers and permanently deleted immediately after the transaction is complete. We do not persist customer data.
How much does the Java invoice OCR API cost?
Our service uses a simple pay-as-you-go model. You can view our full pricing details to find a volume tier that fits your AP automation needs. All new accounts get free credits for testing.
More OCR Tutorials
Java Shipping Container OCR API
Tutorial: Learn how to use the StructOCR Java Client to extract data from Shipping Containers. Extract ISO 6346 container numbers with 99% accuracy.
Java Driver 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 HIN (Hull Identification Number) OCR API
Tutorial: Learn how to integrate the StructOCR API into your Java enterprise applications to extract structured data from Hull Identification Numbers (HIN).
Java National ID Parser API
Eliminate manual data entry for national IDs. Our Java ID card parsing API provides AES-256 encrypted JSON output in <5s average latency, ensuring SOC2 compliant verification.
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