Skip to content

Extracting PDFs and scans

PDFs are the main case and the one where routing matters most. A single file often mixes born-digital pages with scanned ones; Deskew decides page by page.

Terminal window
curl https://api.deskew.dev/v1/extract \
-H "Authorization: Bearer $DESKEW_API_KEY" \
-F "file=@contract.pdf" \
-F "output=json" \
-F "bbox=true"

Pages with a usable text layer are read with the text-layer engine: text with positions comes from the PDF itself, lines are grouped into paragraphs and headings by font size and spacing, and ruled tables are detected from the page’s lines. Bounding boxes are exact. These pages cost 1 credit and typically take well under a second.

A page is digital when enough of its area is covered by text boxes and the text is not garbage (no replacement characters, dictionary-like tokens). If a page passes that check but then yields no text, it is treated as scanned and OCR’d.

Scanned pages are rendered, scored and prepared before OCR:

  • Quality score from effective resolution, blur (Laplacian variance), contrast and skew angle. It is returned as page_results[].quality_score (0–1, higher is better).
  • Deskew and rotate: the detected skew angle is corrected before OCR.
  • OCR with deskew-ocr. The output is validated for repetition loops, implausible length and empty output; a failure triggers one retry on an enhanced image (contrast equalisation, denoise, upscale), then escalation to premium on paid plans.
  • Confidence is returned per page. A first pass below 0.72 triggers the retry (and escalation on paid plans). A page whose output still fails validation after that is marked low_confidence: true and carries a page N: low_confidence: … entry in warnings[].

Bounding boxes on scanned pages come from the OCR model and are approximate. Blocks carry meta.bbox_source: "vlm-approx" so you can tell them from text-layer boxes.

Send the password as a form field or in options:

Terminal window
curl https://api.deskew.dev/v1/extract \
-H "Authorization: Bearer $DESKEW_API_KEY" \
-F "file=@statement.pdf" \
-F "pdf_password=s3cret"
{ "url": "https://example.com/statement.pdf", "options": { "pdf_password": "s3cret" } }

The password is used only in worker memory and never logged; it is excluded from request logs and from the idempotency hash. A PDF that needs a password you did not supply fails with 422 password_protected.

Situation Result
PDF has 0 pages 422 empty_document
More than 2,000 pages 422 too_many_pages
Cannot be opened 422 corrupt_file
Wrong or missing password 422 password_protected
Over 20 MB or more than 12 work units Queued as a job (202) unless mode=sync, which returns 413 sync_limit_exceeded
A single page cannot be read Counted in pages.failed; the job still completes
  • page_results[].engine tells you which path each page took. A document that is all text-layer is exactly as reliable as its text layer.
  • page_results[].low_confidence and warnings[] flag pages to review by hand.
  • usage.engines summarises the mix, for example {"text-layer": 10, "deskew-ocr": 2}.