Node.js and browser, no SDK required

OCR API JavaScript: Extract Text and Data from PDFs in Node.js

Call DocuOCR from JavaScript with the built-in fetch: POST a PDF or image, start extraction, and read structured JSON back with named fields, tables and confidence scores. No OCR engine to bundle, no npm SDK to wire.

The same endpoint reads digital and scanned PDFs, so one code path handles both. Copy the Node.js below and run it against your own document. Last updated July 2026.

  • Three fetch calls, JSON out
  • Fields, tables and confidence
  • Reads scans and native PDFs
  • Webhooks for batch at scale
Try it now, no signup

PDF, JPG, PNG, BMP, HEIC, TIFF

Upload a document to extract

See the JSON your fetch call would receive, right in the browser.

SOC 2 Type II
256-bit encryption
US data handling
REST and JSON
3 calls
upload, extract, get JSON
0 SDKs
built-in fetch is enough
1 endpoint
scans and digital PDFs alike
JSON
fields, tables, confidence
// The short answer

How to call an OCR API from JavaScript

To use an OCR API in JavaScript, you send a document to an HTTPS endpoint and read the recognized data back as JSON, all through the fetch that ships with Node.js 18 and up and every browser. There is no OCR engine to bundle, no model to train, and with a REST API like DocuOCR no npm SDK to add. You authenticate with a Bearer API key, POST the file as FormData to get a file_id, start an extraction job, then poll or receive a webhook for the result. Because the response is JSON, await response.json() turns it into a plain object of named fields, table rows and confidence scores you can drop straight into a database, a spreadsheet 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.

The three calls

  • Upload: POST the file, get a file_id.
  • Extract: POST the file_id, get a job hash.
  • Get: poll or webhook for the JSON.
// Copy and run

OCR a PDF in Node.js with the DocuOCR API

Three fetch calls, from a file on disk to structured JSON. Runs on Node 18+ with no dependencies. Swap in your API key from the dashboard and point it at any PDF or image.

ocr_pdf.mjs
import { readFile } from "node:fs/promises";

const API_KEY = "YOUR_API_KEY";
const BASE = "https://docuocr.com/api/documents";
const auth = { Authorization: `Bearer ${API_KEY}` };

// 1. Upload the PDF or image, get a file_id
const form = new FormData();
form.append("file", new Blob([await readFile("invoice.pdf")]), "invoice.pdf");
const up = await fetch(`${BASE}/upload`, { method: "POST", headers: auth, body: form });
const { file_id } = await up.json();

// 2. Start extraction, get a job hash
const job = await fetch(`${BASE}/extract`, {
  method: "POST",
  headers: { ...auth, "Content-Type": "application/json" },
  body: JSON.stringify({ file_id }),
});
const { extraction_hash } = await job.json();

// 3. Poll until the JSON is ready
let res;
do {
  await new Promise(r => setTimeout(r, 2000));
  res = await (await fetch(`${BASE}/extraction/${extraction_hash}`, { headers: auth })).json();
} while (res.status !== "completed");

// res.fields and res.tables are ready to use
for (const field of res.fields) {
  console.log(field.name, field.value, field.confidence);
}

That is the whole integration. For a production batch, wrap each call in try or catch, add exponential backoff on HTTP 429, 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. Prefer Python? The same flow in the OCR API Python guide uses requests.

// JavaScript support, compared

Every major OCR API's npm package

The cloud providers ship an npm SDK; a REST API needs only the built-in fetch. What you get back differs more than the language does. Package names verified July 2026.

OCR API npm package What it returns Best for
DocuOCR fetch (built into Node 18+, no SDK) Named fields, tables and confidence as JSON Fields plus tables from one call, scans included
Google Cloud Vision @google-cloud/vision Text and bounding boxes, no named fields Raw text OCR on the Google stack
Google Document AI @google-cloud/documentai Text plus entities, needs a service account Google-native document pipelines
AWS Textract @aws-sdk/client-textract Text, forms and tables as blocks AWS-stack teams already on the v3 SDK
Azure AI Document Intelligence @azure-rest/ai-document-intelligence Text, layout and prebuilt-model fields Azure-stack, prebuilt invoice or receipt models
Mistral Document AI @mistralai/mistralai Markdown plus structured output LLM-based parsing of mixed content
Tesseract (tesseract.js) tesseract.js (WASM, browser + Node) Plain text only, runs client-side Free, low-volume, offline or in-browser

The split that matters: raw OCR APIs like Google Cloud Vision and tesseract.js return text and coordinates, so you write the field mapping in JavaScript 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.

// How it works

From a file to a JavaScript object in four steps

1. Authenticate

Generate a key in the dashboard and send it as a Bearer token in the Authorization header.

2. Upload

POST a PDF, PNG, JPG, TIFF or WEBP as FormData and read the file_id from the JSON.

3. Extract

POST the file_id to start an async job and get an extraction_hash back.

4. Read JSON

Poll or receive a webhook, then await response.json() gives you fields, tables and confidence.

// Where teams use it

What JavaScript developers build on an OCR API

Node.js pipelines

A background worker posts each incoming file, reads the JSON, and writes fields to a database with no manual entry.

SaaS upload flows

A web app lets users drop a PDF, forwards it server-side to the OCR API, and returns clean fields to the front end.

Accounts payable

A script pulls invoices from an inbox or bucket, extracts totals and line items, and posts them to QuickBooks or an ERP.

Table capture

A data service turns scanned statements and reports into rows and columns for export to Excel, CSV or a warehouse.

Serverless functions

A Lambda or edge function reads a document on upload and returns structured JSON without hosting an OCR engine.

Compliance and KYC

A verification flow reads IDs and forms, checks confidence scores, and routes low-confidence values to a human.

// Frequently asked

OCR API JavaScript FAQ

How do I use an OCR API in JavaScript?
You call it over HTTPS with fetch, which is built into Node.js 18 and up and every modern browser, so there is no client to install. Send your API key as a Bearer token, POST the PDF or image to the upload endpoint, start extraction, then read the JSON back. With DocuOCR that is three short calls: upload returns a file_id, extract returns a job hash, and a GET returns named fields, tables and confidence scores as a JavaScript object you use directly.
What is the best OCR API for Node.js?
The best OCR API for Node.js depends on what you need back. For plain text in the browser or on a server with no API cost, tesseract.js runs the Tesseract engine in WebAssembly. For structured fields and tables from real business documents, a hosted API returns cleaner data with no engine to bundle: DocuOCR posts a document and returns named fields and table rows as JSON from one fetch call, while Google Cloud Vision, AWS Textract and Azure each need their own npm SDK and more setup.
Is tesseract.js good enough for production OCR?
tesseract.js is genuinely useful for plain text from clean images and it runs client-side for free, which no hosted API does. Its limits show on real documents: accuracy drops on faint scans, unusual fonts and dense tables, the WASM engine and language data are heavy to ship, and it returns a block of text, not the invoice number or total as a labeled value. When you find yourself writing regular expressions over the tesseract.js output to pull out fields, you have outgrown raw OCR and want a document extraction API.
Do I need an npm package to call an OCR API?
No. A REST OCR API only needs an HTTPS client, and Node.js 18+ ships a global fetch (stable in Node 22 LTS), so DocuOCR is called with nothing extra installed. The cloud providers publish npm SDKs (@google-cloud/vision, @google-cloud/documentai, @aws-sdk/client-textract, @azure-rest/ai-document-intelligence, @mistralai/mistralai) that help if you are already on that cloud but add a dependency and its own auth model.
How do I handle rate limits and retries in Node.js?
Wrap each request in try or catch and add exponential backoff on HTTP 429 and 5xx responses, honoring any Retry-After header. For batches, run documents through a concurrency-limited queue (for example p-limit or a small worker pool) rather than firing every request at once so you stay under the per-second limit. DocuOCR also supports webhooks, so at scale you register a callback URL instead of polling and let results arrive as each document finishes.
Can a JavaScript OCR API read scanned PDFs and images?
Yes. A document OCR API reads native PDFs, scanned PDFs and image files (PNG, JPG, TIFF, WEBP) through one endpoint. For a digital PDF it reads the embedded text, and for a scan it runs OCR on the page image. DocuOCR returns the same JSON either way, so your Node.js code does not branch on how the document was created.
How do I OCR a file uploaded in the browser?
Take the File from an input or drop event, put it in a FormData object, and POST it to the OCR API from your server (keep the API key server-side, never in client code). In Node your handler forwards the upload to DocuOCR, starts extraction and returns the structured JSON to the front end. For quick client-only text with no server and no key, tesseract.js can run in the browser, though it returns plain text rather than named fields.
How much does an OCR API cost to run from JavaScript?
You pay per page or per document, not per line of code, so the language does not change the price. Raw text OCR runs about $1.50 per 1,000 pages at Azure, AWS and Google, Mistral is $4 per 1,000, and structured extraction runs higher. DocuOCR bills per page on a plan, roughly $14 to $20 per 1,000 pages, and includes fields and tables in that rate. tesseract.js has no per-page fee because it runs on your own hardware, trading the cost for setup and accuracy.
What does a JavaScript OCR API return?
A good document OCR API returns JSON, which becomes a plain object after await response.json(). DocuOCR returns named fields (invoice number, date, totals), table rows with cells kept in order, and a confidence score on each value so you can flag anything below a threshold for review. Raw OCR APIs like Google Cloud Vision and tesseract.js return text and bounding boxes but not named fields, so you write the mapping yourself.

Ship OCR from JavaScript this afternoon

Generate an API key, paste the three fetch calls above, and read structured JSON back in minutes. No engine to bundle, no SDK to learn, and a free tier to test the integration before you pay per page.