How to Extract Tables from PDF Using Python | A 2026 Guide
How to Extract Tables from PDF in Python — 8 Libraries Tested & Compared in 2026
Python PDF Table Extraction : An Introduction
Extracting tables from PDFs is one of those tasks that sounds simple until you actually try it.
PDFs were designed for print fidelity, not data portability. A table inside a PDF is just a collection of text fragments, lines, and coordinates arranged to look like a grid; there is no native "table" object to grab.
That gap between appearance and structure is why Python PDF table extraction remains surprisingly hard in 2026. The ecosystem has matured, but no single library wins across every scenario: scanned documents break most open-source tools, borderless tables confuse coordinate-based parsers, and multi-page tables still get split into disconnected chunks.
This guide benchmarks 8 libraries (open-source, commercial, and AI-powered) against real documents. For each, you will find the installation steps, a working code snippet, a breakdown of strengths and limitations, and a recommendation for when to use it.
Quick Comparison: 8 Python PDF Table Extraction Libraries (2026)
TL;DR: For digital PDFs with structural line objects, use pdfplumber (or Camelot if you need its visual debugger). For a zero-config LLM-ready pipeline, use PyMuPDF4LLM or LLMWhisperer V2. For open-source AI extraction including scanned PDFs, use Surya / Marker. pypdf alone is not a table extraction tool; it is included here because it is what most developers install first.
| Python Library | Approach | Scanned PDF | Borderless Tables | Multi-page Tables | Setup Complexity | Output Format | Best For |
|---|---|---|---|---|---|---|---|
| pypdf | Pure-Python text layer parsing | No | No | No | Very Low | Plain text, strings | Text/metadata extraction; not suited for tables |
| Camelot | Computer vision / coordinate | No | Limited (stream mode) | No | Medium (Ghostscript required; pdfium backend optional) | DataFrame, CSV, JSON, Excel | Bordered tables in digital PDFs with actual line objects |
| Tabula | Java-based coordinate parsing | No | Limited | Partial | Medium (Java JRE) | DataFrame, CSV, JSON, TSV | Quick extraction, multi-page docs |
| pdfplumber | pdfminer layout analysis | No | Yes (configurable) | Partial | Low | List of lists, DataFrame | Complex layouts, custom pipelines |
| unstructured | Layout analysis + OCR | Yes (hi_res) | Yes | Partial | Medium (optional system deps) | Elements, HTML, JSON, CSV | Mixed document pipelines, LLM preprocessing |
| PyMuPDF4LLM | MuPDF rendering + layout engine | Partial (hybrid OCR) | Partial | Partial | Very Low | Markdown, JSON, TXT | LLM / RAG pipelines, modern stacks |
| Surya / Marker | VLM (650M params) + OCR | Yes | Yes | No | High (GPU/llama.cpp) | Markdown, JSON, HTML | Open-source AI table extraction |
| LLMWhisperer | AI + OCR, layout preserving | Yes | Yes | Yes | Very Low (API key) | Layout-preserved text | Complex/irregular tables for LLMs |
Why PDF Table Extraction Is Still Hard in 2026
The root problem has not changed: PDFs encode visual appearance, not semantic structure.
When a designer draws a table, the PDF stores each cell’s text at specific XY coordinates with font metrics. There is no
| Axis | What we measured |
|---|---|
| Ease of setup | Installation steps, system dependencies, time to first result |
| Extraction accuracy | Completeness and correctness of cell content vs. source |
| Structure preservation | Whether rows, columns, and merged cells survived extraction |
| Scanned/image support | Whether the tool can process image-only PDFs |
| Multi-page table handling | Whether tables spanning pages are merged or split |
| LLM readiness | Whether output can feed directly into an LLM prompt without post-processing |
pypdf
pypdf is a free, pure-Python PDF library capable of splitting, merging, cropping, transforming, encrypting, and extracting text and metadata from PDF files. It is the successor to PyPDF2 (merged back under the pypdf name) and is the most widely-installed PDF package in Python by download count.
Important caveat before you read further: pypdf has no built-in table detection or table extraction. It reads the raw text layer of a PDF but has no awareness of rows, columns, or cell boundaries. It is included in this guide because it is the first package most developers install when they need "something from a PDF" and understanding what it can and cannot do saves a lot of wasted effort.
What pypdf is Good For
- Extracting raw text from digital (non-scanned) PDFs
- Reading and writing PDF metadata
- Splitting, merging, and rotating pages
- Filling PDF form fields
- Encrypting/decrypting PDFs
- Cropping page regions for pre-processing before passing to a table extractor
Installation
# Installation is done with pip, no system-level dependencies required.
pip install pypdf
Core Extraction Approach
pypdf parses the PDF’s internal content streams and reconstructs text by reading character codes, their font mappings, and positioning operators. It does not analyze spatial layout; it simply concatenates glyphs in stream order. For clean, single-column documents this produces readable text. For tables, it typically produces garbled strings where cell content runs together or appears in the wrong order.
Code Example
from pypdf import PdfReader
reader = PdfReader("path/to/document.pdf")
for page in reader.pages:
text = page.extract_text()
print(text)
What the code does:
PdfReaderopens the file and provides access to pages and metadata.page.extract_text()returns a plain string of the page’s text content – no structure.- The
visitor_textcallback receives each text fragment with its XY position, which you can use to build a crude grid manually. - The
PdfWritercrop pattern shows the most practical use of pypdf alongside table extractors: pre-processing a page to isolate the region you care about, then handing the cropped PDF to a specialist tool.
Strengths
- Zero dependencies – pure Python, installs everywhere
- Best-in-class for PDF manipulation: merge, split, rotate, encrypt, form-fill
- Very fast for text extraction on clean documents
- Excellent for metadata reading and PDF introspection
- Works as a pre-processing step for other extractors
Limitations
- No table detection – extracts raw text only, no row/column awareness
- Text order can be incorrect for multi-column layouts or tables
- Cannot process scanned (image-only) PDFs
- No DataFrame output; all results are strings
Ideal Use Case
Use pypdf when you need to manipulate PDFs (merge, split, crop, encrypt) or extract plain text from simple single-column documents. As a table extractor, it is not fit for purpose – but as a pre-processing companion (page cropping, page selection, splitting large files), it is genuinely useful.
Camelot
Camelot is a Python library built specifically for PDF table extraction. It uses two distinct algorithms: lattice for bordered tables and stream for borderless ones, and provides a visual debugging interface that makes it one of the most developer-friendly options for digital PDFs.
Key features
- Lattice mode: uses computer vision to detect table borders and intersections
- Stream mode: infers columns from whitespace gaps (useful for borderless tables)
- Visual debugging:
camelot.plot()renders detected cells and lines for manual inspection - Export to CSV, JSON, Excel, and HTML directly from the API
- Accuracy reporting per table via
table.parsing_report
Installation
Camelot requires Ghostscript to be installed at the OS level before the Python package will work.
# Install Ghostscript via package manager (e.g., apt, brew)
# Then install the Python package:
pip install camelot-py
dependencies = 'ghostscript'
Core Extraction Approach
Camelot’s lattice mode converts the PDF page to an image, runs edge detection to find horizontal and vertical lines, computes cell intersections, and maps text fragments into cells. The stream mode skips line detection and clusters text by x-coordinate proximity instead.
Code example
import camelot
tables = camelot.read_pdf("path/to/document.pdf")
# Access table data
for table in tables:
print(table.df)
What the code does:
camelot.read_pdf()reads the PDF and returns a TableList object – a collection of Table instances.table.parsing_reportgives a per-table accuracy score, whitespace ratio, and order number.table.dfreturns the table as a pandasDataFrame, ready for analysis or export.flavor="stream"switches to the whitespace-based algorithm for borderless tables.
Strengths
- Highest accuracy among open-source tools for bordered, digital PDFs
- Visual debugging saves hours of manual checking
- Direct pandas integration – no format conversion needed
- Per-table accuracy score helps filter low-confidence results
Limitations
- No OCR: fails entirely on scanned or image-based PDFs
- Ghostscript dependency: adds OS-level setup friction in CI/CD pipelines
- Multi-page tables: each page is treated independently; cross-page tables must be merged manually
- Stream mode requires tuning (
edge_tol,row_tol) for complex layouts
Tabula
Tabula started as a browser-based table extraction app and grew into a widely-used Java library (tabula-java) with an official Python wrapper (tabula-py). It’s fast, well-documented, and handles multi-page documents cleanly – but requires a Java runtime.
Key features
- Two detection algorithms:
lattice(ruled lines) andstream(whitespace) - Returns tables as a list of pandas DataFrames – one per detected table
- Multi-page extraction with
pages="all" - Batch processing: convert entire directories of PDFs to CSV/JSON
- Remote PDF support: can fetch and extract from a URL directly
Installation
You need Java 8 or later installed and available on your system PATH.
# Java installation instructions here
# Then install the Python wrapper:
pip install tabula-py
Core Extraction Approach
tabula-py is a thin wrapper around tabula-java. When you call read_pdf(), it spawns a Java subprocess that parses the PDF’s internal structure, identifies table regions using line or whitespace detection, and returns the results as a list of DataFrames serialized through a JSON intermediary.
Code Example
import tabula
tables = tabula.read_pdf("path/to/document.pdf", pages="all")
# Access table data
for table in tables:
print(table)
What the code does:
tabula.read_pdf()processes the PDF via the Java backend and returns a Python list of DataFrames.multiple_tables=Trueensures each distinct table region is returned as its own DataFrame (default is True in recent versions).
Strengths
- Excellent multi-page document handling – one call covers the entire document
- Batch directory processing built in
- Stream algorithm handles many borderless tables without configuration
Limitations
- Java dependency: adds setup complexity and startup latency per call
- No OCR: cannot process scanned documents
- Table boundary ambiguity: stream mode sometimes merges adjacent tables or splits a single wide table
pdfplumber
pdfplumber is built on top of pdfminer.six and gives you fine-grained access to every character, line, rectangle, and curve on a PDF page. Its table extraction is highly configurable: you can define custom cell boundaries, filter by region, and adjust the heuristics that control row and column detection. It is the most flexible open-source option tested.
Key features
- Access to raw character positions, lines, curves, and rectangles
- Table extraction with fully configurable
TableSettings(line strategies, snap tolerance, join tolerance) - Region cropping: extract tables only from specific page areas using bounding boxes
- Debug visualization: render detected table boundaries as an annotated image
- Lossless preservation of merged-cell structure better than most alternatives
Installation
# Simply install via pip:
pip install pdfplumber
Core Extraction Approach
pdfplumber maps every character on the page to an XY coordinate. Its table detector then looks for horizontal and vertical lines (from PDF drawing commands), snaps nearby text to those lines within a configurable tolerance, and assembles the result into a grid. Where lines are absent, you can instruct it to infer boundaries from text spacing instead.
Code Example
import pdfplumber
with pdfplumber.open("path/to/document.pdf") as pdf:
for page in pdf.pages:
tables = page.extract_tables()
for table in tables:
print(table)
What the code does:
pdfplumber.open()returns a context manager giving access to a PDF object with a .pages list.page.extract_tables()returns a list of tables; each table is a list of rows; each row is a list of cell strings.table_settingsis a dictionary that controls how lines are detected and snapped – the most powerful customization lever in pdfplumber.page.crop()restricts extraction to a bounding box, which is essential when a page mixes prose and tables.
Strengths
- Most configurable open-source option – you can handle nearly any layout with the right settings
- No system dependencies beyond Python packages
- Excellent for pages with mixed text and table content
Limitations
- No OCR: works only on text-based PDFs
- Verbosity: complex layouts require significant settings tuning
- Performance: character-level processing is slower than for instance Tabula on large documents
unstructured.io
unstructured is an open-source Python library from Unstructured.io built for extracting and preprocessing content from a wide range of document formats (PDFs, DOCX, HTML, Markdown, images, and more) and feeding that content into LLM and RAG pipelines. Its PDF parser supports multiple extraction strategies, ranging from a fast text-layer pass to a full layout-detection + OCR pipeline that handles scanned documents and complex table structures.
Key features
- Three PDF strategies:
fast(text layer only),hi_res(layout detection + OCR), andocr_only(OCR across the whole page) - Table extraction:
hi_resstrategy withinfer_table_structure=Truereturns tables as HTML strings with full cell structure - Structured Elements API: every extracted piece of content – title, paragraph, table, list item – is typed (
Table, Text, Title, NarrativeText, etc.) - LangChain and LlamaIndex integration out of the box
unstructured-ingest CLIand Python API for batch pipeline processing- Supports 20+ document formats with a unified API
Installation
# Install via pip:
pip install unstructured
Core Extraction Approach
unstructured applies a multi-stage document understanding pipeline. In hi_res mode, it renders each page as an image, runs a layout detection model to identify text blocks and table regions, then applies OCR to each detected element. Table regions are parsed into HTML using the detected cell structure. In fast mode, it falls back to pdfminer-style text extraction, faster, but with no awareness of table boundaries.
Code Example
from unstructured.partition.pdf import partition_pdf
tables = partition_pdf("path/to/document.pdf", strategy="hi_res", infer_table_structure=True)
# Access table data
for table in tables:
print(table)
What the code does:
partition_pdf()is the main entry point. It returns a list of typed Element objects – one per logical content block detected on each page.strategy="hi_res"activates the layout detection + OCR pipeline.infer_table_structure=Trueinstructs the table detector to output the full HTML cell structure rather than just the flattened text.table.metadata.text_as_htmlholds the complete<table>…</table>HTML for each detected table, preservingcolspanandrowspanwhere detected.
Strengths
- Unified API across 20+ document formats – one library for PDFs, DOCX, HTML, and more
- Open-source and fully local – no API key, no data upload
hi_resstrategy handles scanned PDFs and borderless tables- Typed Elements API makes it easy to filter for specific content (tables, titles, lists)
Limitations
- Setup complexity in
hi_resmode: requires Tesseract, Poppler, and a layout detection model – significantly more setup than fast mode - Speed:
hi_resis slow on large documents without a GPU; fast is quick but misses borderless tables and scanned content - Table output is HTML: if you need a pandas DataFrame directly, you must parse the HTML (e.g., with
pd.read_html())
PyMuPDF4LLM
PyMuPDF4LLM is a lightweight extension for PyMuPDF (the Python bindings for the MuPDF rendering library) that converts PDFs into clean, structured output (Markdown, JSON, or plain text) with automatic table detection, layout analysis, and optional hybrid OCR. It is purpose-built for LLM and RAG pipelines and is the newest entry in this comparison.
Key features
- Automatic table detection – no configuration required for most PDFs
- Tables render as GitHub-Flavored Markdown in
to_markdown()output to_json()returns cell-level bounding boxes and layout metadata for custom pipelines- Hybrid OCR: automatically OCRs only image-covered or illegible regions, skipping clean text
- Layout analysis reconstructs reading order across single and multi-column pages
- LangChain and LlamaIndex integration out of the box
Installation
# Install via pip:
pip install pymupdf4llm
Core Extraction Approach
PyMuPDF4LLM uses MuPDF’s rendering engine to analyze the visual structure of each page. Table detection works by identifying ruled lines, consistent column alignment, and regular row spacing; similar to Camelot’s lattice mode but without requiring Ghostscript. The output is designed to be fed directly into LLM context windows: tables come out as Markdown tables that modern LLMs understand natively.
Code Example
import pymupdf4llm
tables = pymupdf4llm.to_markdown("path/to/document.pdf")
# Access table data
print(tables)
Strengths
- Zero configuration for most documents – tables just work
- Output is directly LLM-ready (Markdown tables)
- Hybrid OCR handles mixed digital/scanned pages automatically
- No system dependencies
Limitations
- Borderless table detection: defaults to layout mode, but inconsistently spaced borderless tables may still render as plain text – switch
use_layout(True)or fall back toto_json()for manual post-processing - Multi-page tables: tables are detected per-page; cross-page merging requires custom code
- Less configurable than for instance pdfplumber for edge cases
Ideal Use Case
Building LLM or RAG pipelines where the extracted content goes directly into a prompt or a vector store. Also the fastest path from PDF to LLM-ready Markdown when you do not want to write post-processing code.
Surya / Marker (DataLab)
Surya and Marker are two complementary open-source libraries from DataLab. Surya is the underlying AI model, a 650-million-parameter vision-language model (VLM) that handles OCR, layout analysis, reading-order detection, and table recognition across 90+ languages. Marker is the higher-level document converter that uses Surya under the hood and exposes a clean TableConverter API for extracting tables directly from PDF files as Markdown, JSON, or HTML.
Together they represent the most capable fully open-source, locally-runnable AI table extractor available in 2026.
Key features
- Fully local – no data leaves your machine
- OCR built in – works on scanned and image-only PDFs
- HTML table output with full spanning cell support (
colspan,rowspan) - 90+ language support
- marker
TableConverter: extracts only tables, output as Markdown/JSON/HTML - Apache 2.0 code license; model weights under modified OpenRAIL-M
Installation
# Install as dfault:
pip install surya-marker
# Backend setup (optional for GPU):
pip install llama-cpu
Core Extraction Approach
Surya renders each PDF page as an image, then passes the image to the VLM, which identifies table regions, detects cell boundaries, and extracts text; all in one forward pass. The simple mode returns row/column bounding boxes; full mode generates a complete HTML table including merged cells. Marker’s TableConverter wraps this pipeline and adds page-level orchestration, multi-format output, and batch processing.
Code Example
import surya_marker
tables = surya_marker.TableConverter("path/to/document.pdf")
# Access table data
print(tables)
Strengths
- Fully open-source and local – no API key, no data upload, no per-page cost
- Only open-source option tested that natively handles scanned PDFs
- Full HTML table output with spanning cells (colspan, rowspan)
- 90+ language support out of the box
Limitations
- Heavy setup: requires a GPU inference backend (
vllm) orllama.cpp– not a simple pip install scenario - GPU strongly recommended: CPU inference via llama.cpp works but is significantly slower (seconds per page vs. 5+ pages/sec on an RTX 5090)
- Higher memory footprint than coordinate-based tools
LLMWhisperer
LLMWhisperer is an AI-powered document processing API from Unstract. Unlike all other tools in this comparison, it is not a table extractor in the traditional sense; it is a layout-preserving PDF-to-text converter with a dedicated table mode. The output is clean, structured plain text that preserves the original table layout, making it ideal for LLM inference use cases where you want the model to understand the table’s structure without any custom parsing.
V2 is a significant upgrade over V1:
- New
tablemode: a dedicated processing mode optimized for dense table structures - ASCII line markers:
mark_vertical_linesandmark_horizontal_linesdraw ASCII borders around table cells, giving LLMs dramatically better column/row demarcation for merged cells and complex layouts - Async-first API: V2 uses a
whisper_hashpattern – submit a job, poll for completion, retrieve results - New webhook support: register a callback URL to receive results without polling
Installation
# Sign up for an API key at https://unstract.com/llmwhisperer
pip install llmwhisperer
Core Extraction Approach
LLMWhisperer sends your PDF to Unstract’s cloud infrastructure, where it applies OCR (for scanned content), layout analysis, and in table mode, additional processing to identify table regions. The result is plain text where the spatial layout of the original is preserved using spaces. Enabling mark_vertical_lines and mark_horizontal_lines adds ASCII borders around table cells.
Ideal Use Case
Any pipeline where extracted tables will be consumed by an LLM. Especially strong for scanned documents, complex multi-column financial tables, tables with merged cells, and documents where structure varies across pages.
Python Table Extraction: Benchmark Summary
Results from running all libraries against apple.pdf (clean financial statements) and best-unicef-1.pdf (mixed-format annual report):
| Library | apple.pdf | best-unicef-1.pdf | Scanned | Setup Time | Notes |
|---|---|---|---|---|---|
| pypdf | No table output (raw text only) | No table output (raw text only) | No | ~1 min | Not a table extractor; included for completeness |
| Camelot | Failed (lattice) / Partial (stream, column errors) | High accuracy | No | ~5 min | Lattice fails on cosmetic borders; stream mode recovers data with tuning |
| Tabula | Partial (some columns merged) | Good accuracy | No | ~5 min | Java required; stream mode helps |
| pdfplumber | Very high accuracy | Very high accuracy | No | ~2 min | Best open-source for digital PDFs |
| unstructured | Good accuracy (hi_res) | Good accuracy (hi_res) | Yes (hi_res) | ~10 min | hi_res needs Tesseract + layout model; open-source |
| PyMuPDF4LLM | High accuracy (Markdown tables) | High accuracy | Partial | ~1 min | Best for LLM/RAG pipelines |
| Surya / Marker | Very high accuracy | Very high accuracy | Yes | ~30 min | GPU/llama.cpp required; best open-source AI option |
| LLMWhisperer | Very high (table mode) | Very high (table mode) | Yes | ~2 min | Best overall for LLM inference |
Key findings
- pypdf extracted raw text from both documents but produced no table structure whatsoever.
- Camelot failed on apple.pdf because that document uses text-drawn table separators rather than actual PDF line objects.
- Tabula handled both documents but introduced column merge errors on wide tables where whitespace gaps were ambiguous.
- pdfplumber consistently delivered the best accuracy among open-source coordinate tools on both documents, with no additional configuration required.
- unstructured with hi_res strategy extracted tables from both documents with good accuracy.
- PyMuPDF4LLM handled both documents cleanly on bordered tables; its Markdown output was immediately usable in LLM prompts.
- Surya / Marker produced very high accuracy across both documents.
- LLMWhisperer V2 with table mode produced the most accurate LLM-ready output across both documents and handles scanned PDFs identically.
How to Choose the Right Python Library for PDF Table Extraction
No single library wins every scenario. The right choice comes down to four questions about your documents and your pipeline.