Call DocuOCR from Java with the built-in HttpClient: POST a PDF or image, start extraction, and read structured JSON back with named fields, tables and confidence scores. No native OCR binary to install, no cloud SDK to wire.
The same endpoint reads digital and scanned PDFs, so one code path handles both. Copy the Java below and run it against your own document. Last updated July 2026.
Upload a document to extract
Drop files here or click to upload
Up to 50 files
Uploading...
See the JSON your HttpClient call would receive, right in the browser.
To use an OCR API in Java, you send a document to an HTTPS endpoint and read the recognized data back as JSON, all through the HttpClient that ships with the JDK from Java 11. There is no native OCR engine to install, no model to train, and with a REST API like DocuOCR no Maven SDK to add. You authenticate with a Bearer API key, POST the file as multipart form data to get a file_id, start an extraction job, then poll or receive a webhook for the result. Because the response is JSON, you map it onto a record or POJO with Jackson and get named fields, table rows and confidence scores you can drop straight into a database, an export or an accounting workflow. The same three calls work for a native PDF, a scanned PDF or a photo, so your code does not branch on how the document was made.
Three HttpClient calls, from a file on disk to structured JSON. Runs on JDK 11+ with no dependencies. Swap in your API key from the dashboard and point it at any PDF or image.
import java.net.URI;
import java.net.http.*;
import java.nio.file.*;
// Multipart upload omitted for brevity; JSON parsed with your library of choice.
String apiKey = "YOUR_API_KEY";
String base = "https://docuocr.com/api/documents";
HttpClient http = HttpClient.newHttpClient();
// 1. Upload the PDF or image, get a file_id (multipart body built with a boundary)
HttpRequest upload = HttpRequest.newBuilder(URI.create(base + "/upload"))
.header("Authorization", "Bearer " + apiKey)
.header("Content-Type", "multipart/form-data; boundary=X")
.POST(HttpRequest.BodyPublishers.ofByteArray(multipart("invoice.pdf")))
.build();
String fileId = json(http.send(upload, HttpResponse.BodyHandlers.ofString()).body(), "file_id");
// 2. Start extraction, get a job hash
HttpRequest extract = HttpRequest.newBuilder(URI.create(base + "/extract"))
.header("Authorization", "Bearer " + apiKey)
.header("Content-Type", "application/json")
.POST(HttpRequest.BodyPublishers.ofString("{\"file_id\":\"" + fileId + "\"}"))
.build();
String hash = json(http.send(extract, HttpResponse.BodyHandlers.ofString()).body(), "extraction_hash");
// 3. Poll until the JSON is ready
HttpRequest get = HttpRequest.newBuilder(URI.create(base + "/extraction/" + hash))
.header("Authorization", "Bearer " + apiKey).build();
String body;
do {
Thread.sleep(2000);
body = http.send(get, HttpResponse.BodyHandlers.ofString()).body();
} while (!json(body, "status").equals("completed"));
// body now holds fields, tables and confidence as JSON, ready to map with Jackson
System.out.println(body);
That is the whole integration. For a production batch, wrap each call in try or catch, add exponential backoff on HTTP 429, submit through an ExecutorService, and register a webhook instead of the polling loop so results arrive as each document finishes. The document OCR API reference covers the full request and response shape. Working in another language? The same flow in Python or Node.js reads the same JSON.
The cloud providers ship a Maven SDK; a REST API needs only the built-in HttpClient. What you get back differs more than the language does. Artifacts verified July 2026.
| OCR API | Java library (Maven) | What it returns | Best for |
|---|---|---|---|
| DocuOCR | java.net.http.HttpClient (built into JDK 11+) | Named fields, tables and confidence as JSON | Fields plus tables from one call, scans included |
| Google Cloud Vision | com.google.cloud:google-cloud-vision | Text and bounding boxes, no named fields | Raw text OCR on the Google stack |
| Google Document AI | com.google.cloud:google-cloud-document-ai | Text plus entities, needs a service account | Google-native document pipelines |
| AWS Textract | software.amazon.awssdk:textract | Text, forms and tables as blocks | AWS-stack teams on the v2 SDK |
| Azure AI Document Intelligence | com.azure:azure-ai-documentintelligence | Text, layout and prebuilt-model fields | Azure-stack, prebuilt invoice or receipt models |
| Mistral Document AI | No official Java SDK (call REST directly) | Markdown plus structured output via REST | LLM-based parsing of mixed content |
| Tesseract (tess4j) | net.sourceforge.tess4j:tess4j | Plain text only, needs the native binary | Free, offline, low-volume plain text |
The split that matters: raw OCR libraries like Google Cloud Vision and tess4j return text and coordinates, so you write the field mapping in Java yourself. A document extraction API returns named fields and table rows already, which is most of the code you would otherwise maintain. See the full OCR API pricing comparison for what each costs per 1,000 pages.
Generate a key in the dashboard and send it as a Bearer token in the Authorization header.
POST a PDF, PNG, JPG, TIFF or WEBP as multipart form data and read the file_id from the JSON.
POST the file_id to start an async job and get an extraction_hash back.
Poll or receive a webhook, then map the JSON to a record with Jackson: fields, tables, confidence.
A service forwards each uploaded file to the OCR API, maps the JSON to a POJO, and persists clean fields with JPA.
A batch job on the JVM reads invoices and forms overnight and posts totals and line items into an ERP.
A worker pulls invoices from a queue, extracts totals and line items, and routes them for approval with no manual entry.
A data service turns scanned statements and reports into rows and columns for a warehouse or a report.
A Kafka consumer reads a document on arrival and publishes structured JSON downstream with no OCR engine to host.
A verification flow reads IDs and forms, checks confidence scores, and routes low-confidence values to a human.
The full endpoint reference and response shape.
The same three calls from Python with requests.
Call the API from Node.js with the built-in fetch.
An honest roundup of OCR APIs for US teams.
Pull tables from PDFs to Excel, CSV or JSON.
Per-1,000-page rates across the market.
Generate an API key, paste the three HttpClient calls above, and read structured JSON back in minutes. No native binary to install, no SDK to learn, and a free tier to test the integration before you pay per page.