Skip to content
Reading documents 8 min read · LogicSpoke PDF

How to extract structured JSON from any PDF (even messy ones)

TL;DR: ZonalOCR and regex parsers break when vendor layouts change. A modern AI extraction pipeline uses intelligent OCR routing + LLM schema enforcement to return typed JSON every time — regardless of document format. One API call. No template to maintain.

Your automation worked perfectly — until it didn't.

A vendor changed their invoice layout. A supplier started sending scanned PDFs instead of digital ones. A multi-page contract now has tables that span across page breaks. And your carefully crafted ZonalOCR template, your regex pattern, your "Extract text from PDF" node in Make.com — all of it silently started returning garbage data, or nothing at all.

This is the fragile parser problem, and it's the single most common reason document automation workflows fail in production.

Why traditional PDF parsers are always one layout change away from failing

PDF was designed as a print format, not a data format. When a human opens a PDF, they see a clean invoice. When your code opens the same file, it sees a stream of positioned character glyphs with no concept of "rows," "columns," or "fields" — just coordinates.

Traditional extraction tools deal with this in two ways, both fragile:

  1. ZonalOCR / Template-based parsers — Define bounding boxes: "grab the text between pixel coordinates (450, 210) and (700, 240) — that's the invoice total." This works until the vendor changes their font size, adds a logo, or switches accounting software. The zone shifts by 20 pixels and your total field is now empty — or worse, returns the wrong number with no error.
  2. Regex over raw text — Scan for patterns like \\$[\\d,]+\\.\\d{2}. This fails the moment a PDF is scanned (image, not text), uses a European number format, or has amounts in multiple columns.

Neither approach can handle: scanned/image PDFs, handwriting, tables that span page breaks, rotated pages, or variable layouts from 100+ different vendors.

The architecture of a resilient PDF extraction pipeline

Layer 1: intelligent OCR routing

Not all PDFs need the same treatment. A text-heavy contract with a clean digital layer doesn't need expensive vision processing. A scanned invoice does. A properly designed system automatically routes:

  • Digital text PDFs → fast text extraction (1 credit/page)
  • DOCX files → Microsoft-native parsing via Mammoth (free)
  • Scanned / image-heavy PDFs → Azure Document Intelligence OCR (2 credits/page)
  • Complex layouts, handwriting, mixed content → Vision Language Model — the document is rasterized and read by a vision model (20 credits/page)

This routing happens automatically. You don't need to know what kind of PDF you're receiving.

Layer 2: schema enforcement

Raw extracted text is still unstructured. The engine feeds that text to the AI model with a strict JSON Schema defining exactly what fields to extract and their types. If invoiceTotal is defined as { "type": "number" }, you will never receive the string "$1,234.56". You receive 1234.56.

Layer 3: async queue processing

A 50-page contract takes time. Holding an HTTP connection open causes timeouts in Make.com, Zapier, n8n, and virtually every HTTP client. The correct architecture returns a jobId immediately (HTTP 202) and delivers results via webhook when processing completes.

The implementation: PDF to clean JSON in one API call

Synchronous (for documents under ~10 pages)

The endpoint takes a real file upload (multipart/form-data), not a JSON body — in Make/n8n/Zapier's HTTP node, attach the file as form data rather than a raw JSON payload. schema is passed as a JSON string field alongside the file, not a nested JSON object:

curl -X POST "https://api.logicspoke.com/pdf/v1/pdf/parse/sync" \
     -H "Authorization: Bearer YOUR_API_KEY" \
     -F "[email protected]" \
     -F 'schema={
       "type": "object",
       "required": ["vendorName", "invoiceNumber", "invoiceTotal", "dueDate"],
       "properties": {
         "vendorName":    { "type": "string" },
         "invoiceNumber": { "type": "string" },
         "invoiceDate":   { "type": "string", "format": "date" },
         "dueDate":       { "type": "string", "format": "date" },
         "invoiceTotal":  { "type": "number" },
         "taxAmount":     { "type": "number" },
         "currency":      { "type": "string" },
         "lineItems": {
           "type": "array",
           "items": {
             "type": "object",
             "properties": {
               "description": { "type": "string" },
               "quantity":    { "type": "number" },
               "unitPrice":   { "type": "number" },
               "lineTotal":   { "type": "number" }
             }
           }
         }
       }
     }'

Response:

{
  "success": true,
  "parseId": "parse_xyz789",
  "isCached": false,
  "data": {
    "vendorName": "Acme Corp",
    "invoiceNumber": "INV-2024-0892",
    "invoiceDate": "2024-11-01",
    "dueDate": "2024-11-30",
    "invoiceTotal": 4250.00,
    "taxAmount": 382.50,
    "currency": "USD",
    "lineItems": [
      { "description": "Enterprise License Q4", "quantity": 1, "unitPrice": 3500.00, "lineTotal": 3500.00 },
      { "description": "Support Package", "quantity": 1, "unitPrice": 750.00, "lineTotal": 750.00 }
    ]
  },
  "validation": { "valid": true, "missingRequired": [], "invalidDates": [] },
  "usage": { "pages": 2, "creditsUsed": 4 }
}

Asynchronous (for large documents or batches)

The async endpoint is POST /v1/pdf/parse (no /async suffix) — same multipart fields as above. There's no per-request webhookUrl field; instead, register a standing webhook once via POST /v1/webhooks subscribed to the parse.completed event, and it fires for every async job on the account:

curl -X POST "https://api.logicspoke.com/pdf/v1/pdf/parse" \
     -H "Authorization: Bearer YOUR_API_KEY" \
     -F "[email protected]" \
     -F 'schema={ "...": "..." }'

Response — poll GET /v1/pdf/parse/jobs/{jobId} with the returned jobId for the result once it completes (or just wait for the parse.completed webhook if you registered one):

{ "success": true, "jobId": "job_abc123", "status": "pending" }

Your registered webhook (if any) receives the full result when processing completes.

Enabling vision mode for scanned documents

Add -F "vision=true" to any request. The system automatically rasterizes pages and reads them with a vision model. Cost: 20 credits/page.

Schema-by-example: no JSON schema knowledge required

Paste a sample output object as the sampleOutput form field, and the system infers the full schema automatically:

curl -X POST "https://api.logicspoke.com/pdf/v1/pdf/parse/sync" \
     -H "Authorization: Bearer YOUR_API_KEY" \
     -F "[email protected]" \
     -F 'sampleOutput={
       "vendorName": "Acme Corp",
       "invoiceTotal": 1234.56,
       "dueDate": "2024-11-30",
       "lineItems": [{ "description": "Widget A", "amount": 100.00 }]
     }'

Pre-built schema library

Reference a built-in schema by schemaId — no schema definition required. The 10 system schemas, exactly as they exist today:

schemaId Document Type
sys_invoice Vendor invoices, bills
sys_receipt Expense receipts
sys_contract Service agreements
sys_nda Non-disclosure agreements
sys_bank_statement Account statements
sys_expense_report Employee expense reports
sys_resume CV / job applications
sys_job_application Job application forms
sys_meeting_notes Meeting minutes/notes
sys_id_document Passports, driver's licenses (auto-enables Vision mode)
curl -X POST "https://api.logicspoke.com/pdf/v1/pdf/parse/sync" \
     -H "Authorization: Bearer YOUR_API_KEY" \
     -F "[email protected]" \
     -F "schemaId=sys_invoice"

Using this in Make.com, n8n, or Zapier

  1. Trigger: Gmail "Watch Emails" → filter for attachments from vendor domains
  2. HTTP Module (POST to /v1/pdf/parse, the async endpoint):
    • URL: https://api.logicspoke.com/pdf/v1/pdf/parse
    • Header: Authorization: Bearer YOUR_API_KEY
    • Body type: form-data (not JSON) — attach the file under file, plus schemaId: sys_invoice
  3. Register a webhook once (POST /v1/webhooks, subscribed to parse.completed) and it fires for every async job going forward → route the result to Google Sheets, QuickBooks, Airtable

See the full step-by-step module configuration in our No-Code Automation Blueprint.

PII detection built in

Add -F "redact=true" to auto-detect and strip PII from extracted text before it's stored. The finance schemas (sys_invoice, sys_receipt, sys_bank_statement) and the identity schema (sys_id_document) turn this on automatically even if you don't set it. See the PII redaction guide.

Cost comparison

Approach Setup time Accuracy on scanned docs Cost at 500 docs/month
ZonalOCR templates 2–8 hrs/template Low Labor (constantly rebuilding)
Regex over raw text 1–4 hrs Zero Engineering time
Build with Azure + an LLM 3–6 weeks High $150–400/month infra
LogicSpoke Parse API < 20 min High ~$15–50/month

Questions

What happens if the document doesn't contain a required field?

The validation layer returns a missingRequired array. The extraction still succeeds — you get whatever was found plus a structured list of what's missing, so you can route to a human review queue.

Can I pass a raw file instead of a URL?

The API only accepts a real file upload (multipart/form-data) — there's no fetch-by-URL or Base64-in-JSON option. File size limit: 50MB.

Does vision mode work on DOCX files?

Vision mode is automatically skipped for DOCX files — they're parsed natively via Mammoth, which preserves structure better than rasterizing.

Is there a free tier?

Yes — new accounts receive starter credits to test the API. No card required. See Pricing for current amounts.

Ready to extract structured data from your PDFs?

Starter credits included on signup. No card required.