cd /news/ai-tools/extract-tables-from-pdf-invoices-rec… · home › topics › ai-tools › article
[ARTICLE · art-172600] src=dev.to ↗ pub= topic=ai-tools verified=true sentiment=↑ positive

Extract tables from PDF invoices, receipts and bank statements to JSON, with OCR only where it's needed

A developer built an Apify Actor that extracts tables from PDF invoices, receipts and bank statements into JSON and Markdown, using IBM's open-source Docling (layout analysis plus the TableFormer table model) and RapidOCR bundled inside the Actor. The tool applies OCR only to pages lacking an embedded text layer, with auto, always and never modes, and returns one dataset row per document containing tables_json, full_markdown and per-page status. Pricing runs from $0.005 per digital page and $0.02 per OCR page on the free plan, with failed and skipped documents billed at no cost.

key takeaway

The Actor runs Docling's TableFormer layout model plus RapidOCR locally, OCRing only pages without an embedded text layer, and emits one JSON row per document with tables_json, full_markdown and page-level status at $0.005 per digital page and $0.02 per OCR page.

read3 min views3 publishedNov 19, 2026

Getting tables out of PDFs is one of those tasks that looks solved until you try it on real documents:

camelot and tabula work on clean, ruled tables, but miss I built an Apify Actor for this: Invoice, Receipt & PDF Table to JSON / Markdown OCR. It uses IBM's open-source Docling (layout analysis plus the TableFormer table model) and RapidOCR, all bundled inside the Actor. There's no external API key, and documents aren't sent to a third-party AI service. This post shows what comes out and how to call it from Python or an n8n workflow.

Every PDF page is checked for an embedded text layer:

You can force ocrMode: "always" when a PDF's embedded text is garbled, or "never" to skip OCR completely.

One dataset row per document. This is the output for a public sample invoice, shortened:

{
  "file_name": "wordpress-pdf-invoice-plugin-sample.pdf",
  "document_type": "pdf",
  "status": "success",
  "pages_total": 1,
  "pages_digital": 1,
  "pages_ocr": 0,
  "table_count": 3,
  "tables_json": [
    {
      "table_index": 1,
      "page_number": 1,
      "headers": ["Hrs/Qty", "Service", "Rate/Price", "Adjust", "Sub Total"],
      "rows": [
        {
          "Hrs/Qty": "1.00",
          "Service": "Web Design This is a sample description...",
          "Rate/Price": "$85.00",
          "Adjust": "0.00%",
          "Sub Total": "$85.00"
        }
      ],
      "row_count": 1,
      "column_count": 5
    }
  ],
  "full_markdown": "## From:\nDEMO - Sliced Invoices ...\n\n| Hrs/Qty | Service | Rate/Price | Adjust | Sub Total |\n|---|---|---|---|---|\n| 1.00 | Web Design ... | $85.00 | 0.00% | $85.00 |",
  "processing_time_secs": 6.1
}

Some details that save you cleanup work:

Amount and Amount_2, so no cell gets overwritten. Empty cells are null. full_markdown keeps headings, reading order and tables. It works for an LLM prompt or a RAG index."status": "failed" with a reason, and it never stops the rest of the batch. Links must return the file itself, not a preview page. Signed S3 links work, and tokens in links never show up in the log.

import pandas as pd
from apify_client import ApifyClient

client = ApifyClient("<YOUR_APIFY_TOKEN>")
run = client.actor("panix/invoice-table-json-extractor").call(run_input={
    "documentUrls": [
        "https://slicedinvoices.com/pdf/wordpress-pdf-invoice-plugin-sample.pdf",
    ],
    "ocrMode": "auto",
})

frames = []
for doc in client.dataset(run.default_dataset_id).iterate_items():
    if doc["status"] not in ("success", "partial_success"):
        print("failed:", doc["source_url"], doc["error_message"])
        continue
    for table in doc["tables_json"]:
        df = pd.DataFrame(table["rows"])
        df["file"] = doc["file_name"]
        df["page"] = table["page_number"]
        frames.append(df)

print(pd.concat(frames, ignore_index=True).head())

Invoice layouts vary a lot. The most reliable way to get fixed fields such as invoice number, due date, total and VAT is to send full_markdown to an LLM with your schema. The Markdown already has the tables in order, so the prompt stays short.

POST https://api.apify.com/v2/acts/panix~invoice-table-json-extractor/run-sync-get-dataset-items, header Authorization: Bearer <YOUR_APIFY_TOKEN>, body {"documentUrls": ["<link>"]}. tables_json[].rows into items, or an Make and Zapier have Apify apps with a Run Actor action for step 3.

You pay per page that was parsed:

Apify plan Digital page OCR page
Free $0.005 $0.02
Starter $0.0045 $0.018
Business and up $0.0035 $0.014

On top of that there's a start fee of $0.004 per run at the default 4 GB. On the Starter plan, a one-page digital invoice costs $0.0085 and a 3-page scanned statement costs $0.058. Failed and skipped documents are free. If you set a maximum charge per run, the Actor parses only the pages that fit and marks the rest as skipped.

If a document's tables come out wrong, leave a comment or open an issue on the Actor's Issues tab with a similar sample file. I read them all.

── more in #ai-tools 4 stories · sorted by recency
── more on @apify 3 stories trending now
sponsored brought to you by zahid.host 4,200+ EU-deployed projects
reading about agents? ship yours in a single git push.

Run your AI side-project on zahid.host

EU-based hosting, git-push deploys, automatic HTTPS, no cold starts. Free tier with a custom domain — perfect for shipping the agent you just read about.

$git push zahid main
→ Live at https://your-agent.zahid.host ✓
Get free account → Pricing
from €0/mo · no card required
LIVE [news/extract-tables-from-…] indexed:0 read:3min 2026-11-19 · —