PHP and Laravel, no SDK required

OCR API PHP: Extract Text and Data from PDFs and Images

Call DocuOCR from PHP with a few cURL or Guzzle calls: POST a PDF or image, start extraction, and read structured JSON back with named fields, tables and confidence scores. No OCR engine to host, no cloud SDK to wire.

The same endpoint reads digital and scanned PDFs, so one code path handles both, in plain PHP or a Laravel Http call. Copy the code below and run it against your own document. Last updated July 2026.

  • Three cURL or Guzzle calls, JSON out
  • Fields, tables and confidence
  • Reads scans and native PDFs
  • Drops into a Laravel controller or job
Try it now, no signup

PDF, JPG, PNG, BMP, HEIC, TIFF

Upload a document to extract

See the JSON your PHP 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
cURL or Guzzle is enough
1 endpoint
scans and digital PDFs alike
JSON
fields, tables, confidence
// The short answer

How to call an OCR API from PHP

To use an OCR API in PHP, you send a document to an HTTPS endpoint and read the recognized data back as JSON, through cURL that ships with PHP or Guzzle that most projects already have. There is no OCR engine to install, no model to train, and with a REST API like DocuOCR no SDK to add. You authenticate with a Bearer API key, POST the file to get a file_id, start an extraction job, then poll or receive a webhook for the result. Because the response is JSON, json_decode turns it into a PHP array of named fields, table rows and confidence scores you can drop straight into a database, an Eloquent model 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 PHP with the DocuOCR API

Three Guzzle calls, from a file on disk to a structured PHP array. Swap in your API key from the dashboard and point it at any PDF or image. Plain cURL works the same way if you would rather not add a dependency.

ocr_pdf.php
<?php
use GuzzleHttp\Client;

$client = new Client(['base_uri' => 'https://docuocr.com/api/documents/']);
$headers = ['Authorization' => 'Bearer ' . 'YOUR_API_KEY'];

// 1. Upload the PDF or image, get a file_id
$up = $client->post('upload', [
    'headers'  => $headers,
    'multipart' => [['name' => 'file', 'contents' => fopen('invoice.pdf', 'r')]],
]);
$fileId = json_decode($up->getBody(), true)['file_id'];

// 2. Start extraction, get a job hash
$job = $client->post('extract', [
    'headers' => $headers,
    'json'    => ['file_id' => $fileId],
]);
$hash = json_decode($job->getBody(), true)['extraction_hash'];

// 3. Poll until the JSON is ready
do {
    sleep(2);
    $res = json_decode($client->get("extraction/{$hash}", ['headers' => $headers])->getBody(), true);
} while ($res['status'] !== 'completed');

// $res['fields'] and $res['tables'] are ready to use
foreach ($res['fields'] as $field) {
    echo $field['name'], ' = ', $field['value'], PHP_EOL;
}

That is the whole integration. In Laravel the same flow is three Http::withToken()->post() calls in a controller or a queued job. For a production batch, wrap each call in a try or catch block, 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.

// PHP support, compared

Every major OCR API's PHP support

PHP SDK coverage is thinner than Python or Node. AWS and Google ship maintained Composer packages; Azure and Mistral do not, so those are REST-only from PHP. Package status verified July 2026.

OCR API PHP package What it returns Best for
DocuOCR cURL or Guzzle (plain REST, no SDK) Named fields, tables and confidence as JSON Fields plus tables from one call, scans included
AWS Textract aws/aws-sdk-php (official) Text, forms and tables as blocks AWS-stack PHP teams already on the SDK
Google Cloud Vision google/cloud-vision (official) Text and bounding boxes, no named fields Raw text OCR on the Google stack
Google Document AI google/cloud-document-ai (official) Text plus entities, needs a service account Google-native document pipelines
Azure AI Document Intelligence None (SDK retired 2021) - REST only Text, layout and prebuilt-model fields Azure-stack teams willing to call REST
Mistral Document AI None official - REST only Markdown plus structured output LLM-based parsing of mixed content
Tesseract thiagoalessio/tesseract_ocr (local binary) Plain text only Offline, low-volume, no API cost

Two things matter in PHP. First, because Azure and Mistral give you no PHP SDK, you write REST calls for them anyway, so a REST-native API removes the inconsistency of mixing an SDK for one vendor with hand-rolled HTTP for another. Second, raw OCR APIs like Google Cloud Vision return text and coordinates, so you write the field mapping in PHP yourself; a document extraction API returns named fields and table rows already. See the full OCR API pricing comparison for what each costs per 1,000 pages.

// How it works

From a file to a PHP array 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 to the upload endpoint 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 json_decode gives you fields, tables and confidence.

// Where teams use it

What PHP developers build on an OCR API

Laravel document apps

A queued job posts each upload, reads the JSON, and writes fields to the database with Eloquent, no manual entry.

Accounts payable

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

Table capture

A back-office tool turns scanned statements and reports into rows and columns, then exports them to Excel or a database.

SaaS integrations

A PHP SaaS adds a document upload feature that returns clean structured data for its customers with no engine to maintain.

E-commerce and WordPress

A WooCommerce or WordPress plugin reads supplier documents and receipts and files the data without staff typing it in.

Compliance and KYC

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

// Frequently asked

OCR API PHP FAQ

How do I use an OCR API in PHP?
You call it over HTTPS with cURL or Guzzle. Send your API key as a Bearer token, POST the PDF or image to the upload endpoint, start extraction, then read the structured JSON back. With DocuOCR that is three short calls and no SDK to install: upload returns a file_id, extract returns a job hash, and a GET returns fields, tables and confidence scores as JSON your PHP code decodes with json_decode.
What is the best OCR library for PHP?
For plain text off a clean scan, the thiagoalessio/tesseract_ocr wrapper drives a local Tesseract binary for free. For named fields and tables from real business documents, a hosted API returns cleaner data with nothing to host: DocuOCR posts a document and returns structured JSON in one call from plain cURL. AWS Textract (aws/aws-sdk-php) and Google Cloud Vision (google/cloud-vision) ship official PHP SDKs; Azure Document Intelligence and Mistral do not, so those are REST-only from PHP anyway.
Does Azure Document Intelligence have a PHP SDK?
No. Microsoft retired its Azure SDK for PHP in 2021 and it is unmaintained, so the documented way to use Azure AI Document Intelligence from PHP is direct REST calls with cURL or Guzzle. The same is true of Mistral Document AI. Only AWS Textract and Google (Cloud Vision, Document AI) publish maintained PHP packages on Composer, which is why a clean REST API is often the simpler path across all of them in PHP.
How do I extract text from a PDF in PHP?
If the PDF has a real text layer, a library like smalot/pdfparser reads it directly with no OCR. If it is a scanned or photographed PDF, it is an image and needs OCR first. POST it to an OCR API such as DocuOCR, which detects that the page is image-only, runs recognition, and returns the text plus structured fields as JSON. One code path then handles both digital and scanned PDFs.
Can I use an OCR API in Laravel?
Yes. Laravel ships Guzzle through the Http facade, so an OCR API is a few Http::post calls in a controller, job or queued listener. Store the returned file_id, dispatch a queued job to poll or receive a webhook, then persist the extracted fields with Eloquent. Because DocuOCR is plain REST with a Bearer key, there is nothing Laravel-specific to install beyond what a Laravel app already has.
Do I need a PHP SDK to call an OCR API?
No. A REST OCR API only needs an HTTPS client, and PHP has cURL built in plus Guzzle through Composer. DocuOCR is called with either, so there is nothing extra to keep updated. AWS and Google do publish PHP SDKs (aws/aws-sdk-php, google/cloud-vision, google/cloud-document-ai) which help if you are already on that cloud, but they add a dependency and its own auth model.
How do I handle rate limits and retries in PHP?
Wrap each request in a try or catch block and add exponential backoff on HTTP 429 and 5xx responses, honoring any Retry-After header. For large batches, push documents onto a queue (Laravel queues or a worker pool) rather than one tight loop 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.
How much does an OCR API cost to run from PHP?
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. The free tier lets you test the PHP integration before you pay.
What does a PHP OCR API return?
A good document OCR API returns JSON, which PHP turns into an array with json_decode($body, true). 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 return text and bounding boxes but not named fields, so you write the field mapping in PHP yourself.

Ship OCR from PHP this afternoon

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