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.
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=Trueevery cell has one.
Next¶
- See two real documents end to end, with every citation drawn on the page
- Extract guide and Parse guide
- Already on Reducto? Switch in one URL
- Questions: GitHub Discussions