Use this file to discover Exa products, pricing, evaluations, comparisons, use cases, agent interfaces, and technical documentation before exploring further.
Python PDF table extraction libraries find tables on PDF pages and return their rows and cells as data. A text-based extractor reads the characters and ruling lines stored in a digital PDF rather than recognizing text from page images. These libraries let data pipelines and AI agents load tables from reports, invoices, and filings into DataFrames.
Popularity
PyMuPDF has the most monthly downloads in this comparison, at 171.3M, a count that covers all its PDF work.
def main(argv=None):
parser = argparse.ArgumentParser(description="Extract PDF tables to xlsx/csv.")
parser.add_argument("pdf", help="path to the source PDF")
parser.add_argument("--out-dir", default="out", help="directory for output files")
parser.add_argument("--pages", default="", help="page selector, e.g. 2-5 or 1,3")
parser.add_argument("--contains", default="", help="keep only tables containing this text (case-insensitive)")
parser.add_argument("--prefix", default="", help="filename prefix for the output")
parser.add_argument(
"--format",
choices=["xlsx", "csv", "both"],
default="xlsx",
help="output format (default: xlsx, one formatted tab per table)",
)
args = parser.parse_args(argv)
try:
import pdfplumber # noqa: WPS433 (imported lazily so the message is clear)
except ImportError:
sys.exit(
"pdfplumber is required. Install it with `pip install pdfplumber`, "
"or extract the tables manually following the skill's cleaning rules."
)
want_xlsx = args.format in ("xlsx", "both")
workbook = None
if want_xlsx:
try:
from openpyxl import Workbook
except ImportError:
if args.format == "xlsx":
sys.stderr.write(
"openpyxl not available; falling back to CSV output. "
"Install it with `pip install openpyxl` for formatted .xlsx.\n"
)
args.format = "csv"
want_xlsx = False
else:
sys.stderr.write(
"openpyxl not available; producing CSV only.\n"
)
want_xlsx = False
else:
workbook = Workbook()
workbook.remove(workbook.active)
want_csv = args.format in ("csv", "both")
if not os.path.isfile(args.pdf):
sys.exit(f"file not found: {args.pdf}")
os.makedirs(args.out_dir, exist_ok=True)
base = args.prefix or slugify(os.path.splitext(os.path.basename(args.pdf))[0], "document")
needle = args.contains.lower()
tables_out, csv_files, used_titles = [], [], set()
with pdfplumber.open(args.pdf) as pdf:
page_indexes = parse_pages(args.pages, len(pdf.pages))
for page_index in page_indexes:
page = pdf.pages[page_index]
page_number = page_index + 1
tables = page.extract_tables() or []
for table_number, raw in enumerate(tables, start=1):
grid = clean_table(raw)
if not grid:
continue
if needle and needle not in "\n".join(
" ".join(row) for row in grid
).lower():
continue
entry = {"page": page_number, "rows": len(grid), "columns": len(grid[0])}
if want_csv:
csv_name = f"{base}-p{page_number}-t{table_number}.csv"
csv_path = os.path.join(args.out_dir, csv_name)
write_csv(csv_path, grid)
csv_files.append(csv_path)
entry["csv"] = csv_path
if want_xlsx:
title = sheet_title(base, page_number, table_number, used_titles)
worksheet = workbook.create_sheet(title=title)
for row in grid:
worksheet.append(row)
# Force every cell to text so values are preserved # verbatim — otherwise a cell like "=high" or "-5" would # be interpreted by openpyxl/Excel as a formula and lose # its original value. for cell in worksheet[worksheet.max_row]:
cell.data_type = "s"
style_sheet(worksheet, grid)
entry["sheet"] = title
tables_out.append(entry)
xlsx_path = None
if want_xlsx and tables_out:
xlsx_path = os.path.join(args.out_dir, f"{base}.xlsx")
workbook.save(xlsx_path)
summary = {
"source": args.pdf,
"count": len(tables_out),
"xlsx": xlsx_path,
"csv_files": csv_files,
"tables": tables_out,
}
json.dump(summary, sys.stdout, indent=2)
sys.stdout.write("\n")
if not tables_out:
sys.stderr.write(
"No tables matched. Try a different --pages range, drop --contains, "
"or verify the PDF has extractable (non-image) tables.\n"
)
return 1
return 0
Docling
Parses PDF, DOCX, HTML, and other formats into one document representation.
import sys
from docling.document_converter import DocumentConverter
result = DocumentConverter().convert(sys.argv[1])
print([table.export_to_dataframe(doc=result.document) for table in result.document.tables])
Unstructured
Prepares raw documents for machine learning tasks.
import sys
from unstructured.partition.pdf import partition_pdf
elements = partition_pdf(filename=sys.argv[1], strategy="hi_res", infer_table_structure=True)
print([element.metadata.text_as_html for element in elements if element.category == "Table"])
Camelot
Extracts PDF tables using selectable rule-based or optional neural parsers.
Downloads / mo
2.4M
Stars
3.9K
Last release
2.0.0
License
MIT
Strengths
Chooses parsers for different layouts.Use lattice for ruled tables or stream for whitespace-separated tables.
Exports tables directly.Save extracted tables as CSV, JSON, or HTML.
Limitations
Scanned pages need OCR extras.Install the neural and OCR extras, then select the ml parser.
Reads the first page initially.Set pages explicitly to extract tables beyond the first page.
import sys
from paddleocr import PPStructureV3
pipeline = PPStructureV3(use_table_recognition=True)
for result in pipeline.predict(input=sys.argv[1]):
result.save_to_html(save_path="table-output")
FAQ
pdfplumber suits digital PDFs where table settings need tuning against characters and lines. Camelot suits table-only extraction straight into pandas DataFrames. Docling suits whole-document conversion with optional OCR for scanned pages.
Docling converts PDF, DOCX, HTML, and other formats into one document model that includes tables. It runs locally and can use optional OCR backends.
pdfplumber exposes every character, line, and rectangle on a PDF page and finds tables from them. Its extract_tables method returns nested lists of cells rather than DataFrames.
Camelot and tabula-py read PDF tables directly into pandas DataFrames. tabula-py wraps tabula-java and requires a Java runtime.
Camelot is a dedicated PDF table parser that returns pandas DataFrames, with lattice, stream, network, and hybrid parsing modes.
For coding agents
Found your PDF table extraction library? Help your agent use it.
Connect Exa so your coding agent can find the library’s documentation, check its API, and look up implementations while you build.