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

tag, no row object, no column definition.

Extraction libraries must reconstruct structure from visual clues:

Each approach has a different failure mode. Line-based detection fails on borderless tables. Coordinate clustering breaks when columns are unevenly spaced. Layout analysis degrades on multi-column pages where tables and prose are mixed. AI approaches are the most robust but add latency and external dependencies.

What has changed in 2026

Test Documents & Evaluation Criteria

All libraries were tested against two documents:

Apple Inc. annual financial statements. Well-structured tables with clear borders, mixed text and numbers, dense formatting. Represents a typical corporate report.

UNICEF annual report data. Multi-format tables with varying column widths, nested headers, and some borderless sections. Represents messy real-world data.

Evaluation axes

Not every axis applies equally to every use case; a team building a local RAG pipeline cares about LLM readiness and scanned PDF support far more than setup complexity. The six axes below were chosen because together they cover the full lifecycle of a table extraction decision: whether the tool will run in your environment, whether its output can be trusted, and whether that output fits into the pipeline you are building.

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

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:

  1. PdfReader opens the file and provides access to pages and metadata.
  2. page.extract_text() returns a plain string of the page’s text content – no structure.
  3. The visitor_text callback receives each text fragment with its XY position, which you can use to build a crude grid manually.
  4. The PdfWriter crop 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

Limitations

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

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:

  1. camelot.read_pdf() reads the PDF and returns a TableList object – a collection of Table instances.
  2. table.parsing_report gives a per-table accuracy score, whitespace ratio, and order number.
  3. table.df returns the table as a pandas DataFrame, ready for analysis or export.
  4. flavor="stream" switches to the whitespace-based algorithm for borderless tables.

Strengths

Limitations

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

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:

  1. tabula.read_pdf() processes the PDF via the Java backend and returns a Python list of DataFrames.
  2. multiple_tables=True ensures each distinct table region is returned as its own DataFrame (default is True in recent versions).

Strengths

Limitations

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

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:

  1. pdfplumber.open() returns a context manager giving access to a PDF object with a .pages list.
  2. page.extract_tables() returns a list of tables; each table is a list of rows; each row is a list of cell strings.
  3. table_settings is a dictionary that controls how lines are detected and snapped – the most powerful customization lever in pdfplumber.
  4. page.crop() restricts extraction to a bounding box, which is essential when a page mixes prose and tables.

Strengths

Limitations

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

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:

  1. partition_pdf() is the main entry point. It returns a list of typed Element objects – one per logical content block detected on each page.
  2. strategy="hi_res" activates the layout detection + OCR pipeline. infer_table_structure=True instructs the table detector to output the full HTML cell structure rather than just the flattened text.
  3. table.metadata.text_as_html holds the complete <table>…</table> HTML for each detected table, preserving colspan and rowspan where detected.

Strengths

Limitations

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

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

Limitations

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

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

Limitations

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:

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

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.