Skip to content

Extract tables from PDFs

Tables are where plain text extraction breaks: merged header cells, columns without lines, numbers that shift by one row. ReadAnyDoc reads each table with a vision model, re-reads table regions on their own, and checks grids and printed totals without a model.

pip install "readanydoc[engine]"
export ANTHROPIC_API_KEY=...
import readanydoc
from typing import Optional
from pydantic import BaseModel, Field

result = readanydoc.parse("report.pdf")
for table in result.tables:          # blocks of type Table, as HTML
    print(table.content)

# or straight into rows
class Row(BaseModel):
    region: str
    revenue: Optional[float]
    growth_percent: Optional[float]

class Report(BaseModel):
    rows: list[Row]

out = readanydoc.extract("report.pdf", schema=Report, array_extract=True)

print(out.data)            # an instance of your class
print(out.citations)       # where each value was read: text, page, box, confidence
print(out.warnings)        # anything to check

Tips

  • Markdown tables instead of HTML: options={"formatting": {"table_output_format": "md"}}.
  • On RD-TableBench, ReadAnyDoc is level with Reducto (see benchmarks).
  • Each table block has a bounding box; with citations=True every cell has one.

Next