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.

原文来源:dev.to