{"slug": "extract-tables-from-pdf-invoices-receipts-and-bank-statements-to-json-with-ocr-s", "title": "Extract tables from PDF invoices, receipts and bank statements to JSON, with OCR only where it's needed", "summary": "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.", "body_md": "Getting tables out of PDFs is one of those tasks that looks solved until you try it on real documents:\n\n`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](https://apify.com/panix/invoice-table-json-extractor)**. 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.\n\nEvery PDF page is checked for an embedded text layer:\n\nYou can force `ocrMode: \"always\"` when a PDF's embedded text is garbled, or `\"never\"` to skip OCR completely.\n\nOne dataset row per document. This is the output for a public sample invoice, shortened:\n\n```\n{\n  \"file_name\": \"wordpress-pdf-invoice-plugin-sample.pdf\",\n  \"document_type\": \"pdf\",\n  \"status\": \"success\",\n  \"pages_total\": 1,\n  \"pages_digital\": 1,\n  \"pages_ocr\": 0,\n  \"table_count\": 3,\n  \"tables_json\": [\n    {\n      \"table_index\": 1,\n      \"page_number\": 1,\n      \"headers\": [\"Hrs/Qty\", \"Service\", \"Rate/Price\", \"Adjust\", \"Sub Total\"],\n      \"rows\": [\n        {\n          \"Hrs/Qty\": \"1.00\",\n          \"Service\": \"Web Design This is a sample description...\",\n          \"Rate/Price\": \"$85.00\",\n          \"Adjust\": \"0.00%\",\n          \"Sub Total\": \"$85.00\"\n        }\n      ],\n      \"row_count\": 1,\n      \"column_count\": 5\n    }\n  ],\n  \"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 |\",\n  \"processing_time_secs\": 6.1\n}\n```\n\nSome details that save you cleanup work:\n\n`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.\nLinks must return the file itself, not a preview page. Signed S3 links work, and tokens in links never show up in the log.\n\n``` python\nimport pandas as pd\nfrom apify_client import ApifyClient\n\nclient = ApifyClient(\"<YOUR_APIFY_TOKEN>\")\nrun = client.actor(\"panix/invoice-table-json-extractor\").call(run_input={\n    \"documentUrls\": [\n        \"https://slicedinvoices.com/pdf/wordpress-pdf-invoice-plugin-sample.pdf\",\n    ],\n    \"ocrMode\": \"auto\",\n})\n\nframes = []\nfor doc in client.dataset(run.default_dataset_id).iterate_items():\n    if doc[\"status\"] not in (\"success\", \"partial_success\"):\n        print(\"failed:\", doc[\"source_url\"], doc[\"error_message\"])\n        continue\n    for table in doc[\"tables_json\"]:\n        df = pd.DataFrame(table[\"rows\"])\n        df[\"file\"] = doc[\"file_name\"]\n        df[\"page\"] = table[\"page_number\"]\n        frames.append(df)\n\nprint(pd.concat(frames, ignore_index=True).head())\n```\n\nInvoice 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.\n\n`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.\n\nYou pay per page that was parsed:\n\n| Apify plan | Digital page | OCR page | \n|---|---|---|\n| Free | $0.005 | $0.02 | \n| Starter | $0.0045 | $0.018 | \n| Business and up | $0.0035 | $0.014 | \n\nOn 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.\n\nIf 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.", "url": "https://wpnews.pro/news/extract-tables-from-pdf-invoices-receipts-and-bank-statements-to-json-with-ocr-s", "canonical_source": "https://dev.to/panix/extract-tables-from-pdf-invoices-receipts-and-bank-statements-to-json-with-ocr-only-where-its-269o", "published_at": "2026-11-19 14:40:05+00:00", "updated_at": "2026-11-19 14:43:51.754536+00:00", "lang": "en", "topics": ["ai-tools", "developer-tools", "large-language-models", "ai-agents"], "entities": ["Apify", "IBM", "Docling", "TableFormer", "RapidOCR", "camelot", "tabula", "n8n"], "also_reported_by": [], "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.", "recommendation": null, "alternates": {"html": "https://wpnews.pro/news/extract-tables-from-pdf-invoices-receipts-and-bank-statements-to-json-with-ocr-s", "markdown": "https://wpnews.pro/news/extract-tables-from-pdf-invoices-receipts-and-bank-statements-to-json-with-ocr-s.md", "text": "https://wpnews.pro/news/extract-tables-from-pdf-invoices-receipts-and-bank-statements-to-json-with-ocr-s.txt", "jsonld": "https://wpnews.pro/news/extract-tables-from-pdf-invoices-receipts-and-bank-statements-to-json-with-ocr-s.jsonld"}}