174,265 Words to 89,801: pdfplumber's PDF Defaults

📘 Tutorials 2026-12-01 7 min read
174,265 Words to 89,801: pdfplumber's PDF Defaults

The text preview looks fine, but BM25 finds nothing and the chunk token count is half what the page count suggests.

📜 Table of Contents

📖 Keep reading

Open the text pdfplumber returns for the Transformer paper at its default settings and the first line reads Providedproperattributionisprovided,Googleherebygrantspermission…. Every letter is there. Every space between words is gone. Index that with BM25 and a search for "attention" returns nothing; count tokens for a chunk and the estimate is off by about half.

It is not one broken file. Across eight arXiv papers and 353 pages, pdfplumber's default extract_text() returned 89,801 whitespace-separated words. PyMuPDF returned 174,265 on the same files. Character counts were within 3% of each other. The word boundaries were not. Passing x_tolerance=2 brought pdfplumber back to 170,562 words.

What was measured

Eight papers downloaded from arXiv on 1 December 2026: Attention Is All You Need, BERT, GPT-3, InstructGPT, ReAct, GPT-4, LLaVA and a RAG survey. 353 pages, all born-digital, all with an embedded text layer, all English, all two-column academic layout. No OCR was involved.

Four extractors on Python 3.11.6: PyMuPDF 2.2 (MuPDF 1.28.6), pdfplumber 0.11.11, pypdf 7.2.0, pdfminer.six 20260107. Each library read every file once, cold, on the same 2-vCPU Linux machine. Timings are wall clock from one run; read them as ratios, not as a benchmark.

LibraryCharactersWordsSpaces / charsLongest lineTime
PyMuPDF 2.21,114,005174,2650.1321771.9 s
pdfplumber 0.11.11, defaults1,083,98689,8010.06514,25958.1 s
pdfplumber, x_tolerance=21,164,747170,5620.13214,259same run
pypdf 7.2.01,117,549174,7820.13853015.8 s
pdfminer.six 202601071,148,053148,7390.11824,34130.5 s

Why the word count is the number to check

Characters survive almost any extraction. Word boundaries do not. If the text is glued together, three things break at once: whitespace tokenizers in BM25 index a single token providedproperattribution instead of four words, chunkers that split on word counts build chunks twice as large as intended, and any token estimate derived from "words times 1.3" is wrong before the first embedding call.

The gap is large enough to change a pipeline's cost model. 89,801 words against 174,265 is a factor of 1.94. A 10,000-page corpus that should produce roughly 150,000 chunks produces 77,000, each one denser and less searchable than planned.

Failure one: pdfplumber's x_tolerance default of 3

pdfplumber inserts a space when the horizontal gap between two characters is wider than x_tolerance, and the default in pdfplumber/utils/text.py is 3. On tightly justified two-column papers, the gap between words can sit below that threshold, so adjacent words merge. The file is not malformed; the threshold is simply wider than the typography.

Paperpdfplumber defaultx_tolerance=2PyMuPDF
Attention (15 pp)2,0336,1666,095
BERT (16 pp)7,40410,23210,152
GPT-3 (75 pp)14,78337,63538,073
InstructGPT (68 pp)8,27528,76829,491
ReAct (33 pp)11,62417,71117,108
GPT-4 (100 pp)29,33141,95644,223
LLaVA (25 pp)4,50912,67413,505
RAG survey (21 pp)11,84215,42015,618

On the Attention paper the default output was 35,525 characters and 2,033 words. At x_tolerance=2 it was 39,658 characters and 6,166 words. The extra 4,133 characters are spaces that were already in the PDF.

We tried 0.5, 1, 1.5 and 2 on that file. All four produced the same 6,166-word output; 3 was the only setting that collapsed. The fix is one keyword argument, not a different library:

import pdfplumber

with pdfplumber.open("paper.pdf") as pdf:
    text = "\n".join(
        (page.extract_text(x_tolerance=2, y_tolerance=3) or "")
        for page in pdf.pages
    )

Failure two: pdfminer turns a figure into a 24,341-character line

On the ReAct paper, pdfminer returned 159,126 characters against PyMuPDF's 110,287, 44% more. That is not extra content. One line in the output is 24,341 characters long: the labels inside Figure 1 concatenated into a single run with no line breaks. On the GPT-4 paper the longest line is 5,057 characters and the word count falls to 20,252, less than half of pypdf's 44,864, while the character count stays high at 262,225.

For a character-based chunker, that 24,341-character line becomes one chunk. It will be embedded, stored and never retrieved usefully, and it quietly consumes 6,000 or so tokens of every context budget built on top of it.

Failure three: character counts reward the wrong output

pdfplumber's default output contains 5.9% more non-space characters than PyMuPDF (994,193 against 938,997) while carrying 48.5% fewer words. The extra characters are figure and table labels recovered without spaces. A loader that gates on "characters per page" would score the least usable output as the most complete, because it is the one that glued the page together.

Table counts are not reliable either

pdfplumber's extract_tables() found zero tables in the 75-page GPT-3 paper. On InstructGPT it reported 82 tables holding 73 non-empty cells in total, fewer than one cell per table. Attention returned 10 tables and 448 cells. Detection depends on ruling lines and whitespace geometry, so borderless academic tables are either missed or split into fragments. Treat the count as a hint and inspect a sample before trusting it.

Three gates that catch this before indexing

import re

def text_health(text):
    non_space = len(re.sub(r"\s", "", text))
    return {
        "space_ratio": round(text.count(" ") / max(1, len(text)), 3),
        "words_per_1k": round(len(text.split()) / max(1, non_space) * 1000, 1),
        "longest_line": max((len(l) for l in text.splitlines()), default=0),
    }

# measured on this corpus
# PyMuPDF          0.132 / 185.6 / 177
# pypdf            0.138 / 185.5 / 530
# pdfminer         0.118 / 149.8 / 24,341
# pdfplumber       0.065 / 90.3  / 14,259

def looks_broken(t):
    h = text_health(t)
    return h["space_ratio"] < 0.12 or not (140 <= h["words_per_1k"] <= 190) or h["longest_line"] > 500

A gate at 0.12 for the space ratio and 500 characters for the longest line fails every bad output above and passes both clean ones. It costs one regex pass per document.

The thresholds only hold for English prose with a text layer. Code, Chinese and table-heavy documents need their own bands. A scanned PDF has no text layer at all, and none of this applies until OCR has produced one.

What to run

What this test does not cover

Eight English papers with digital text layers. No scans, no forms, no CJK, no rotated pages, no handwriting. One run per library, one machine, and the arXiv files can be revised, so exact counts will drift if the PDFs are downloaded again later. The finding to carry forward is the shape of the failure, not the third decimal place.

Related: scoring Docling, Marker and MinerU on PDF to Markdown, sentence-aligned chunks against 20% overlap, what Trafilatura drops from HTML tables, and FTS5 trigram against porter for code search.

Related Articles
2026-07-22
AI Video Generator Free No Watermark 2026
2026-08-06
Nanobrowser (13,530 Stars) 2026: The Open-Source Chrome Extension for AI-Powered Web Research
2026-07-26
Claude Opus 5: Next Flagship AI
2026-10-21
Best AI Vacation Rental Software in Split 2026: eVisitor Check-ins, 13% VAT and Ferry-Day Turnovers
2026-07-19
LLM Inference Optimization: Make Your Model Run Faster
2026-07-23
AI Coding Assistant Tools Comparison 2026: Which One Should You Use?

Written by our editorial team; tools listed here are tested or verified against public sources. Links point to official sites or GitHub repos for reference only — no paid placements.

💬 Comments (0)

No comments yet. Be the first!

Login to comment