You build a tool that answers questions about documents. Users upload contracts, manuals and papers, almost all of them PDFs. You extract the text, put it in the prompt, and it works. The answers are fine, so you never look closely at the text you send.
You should, because text that comes out of a PDF is not the text the author wrote. It's what a page layout leaves behind, and the model bills you for every piece of that layout.
A few words first
A token is a chunk of text the model reads; APIs bill per million of them. I counted with tiktoken and o200k_base, the tokenizer OpenAI's current models use. Input tokens are what you send to the model. A list price is the vendor's official price per million tokens, before any discount. Text extraction means pulling the characters out of a PDF, with a library or by copy-paste. A PDF stores where each line sits on the page, not where paragraphs begin and end. So what you get back is lines, not paragraphs.
The measurement
I needed a long, real English document, so I used the GNU GPL version 3: 5,644 words, 122 paragraphs. Joined into one line per paragraph, it is 6,701 tokens. That's the clean baseline.
Then I added the usual PDF extraction artifacts one at a time, each on top of the previous ones. I simulated them in a script, because this is what extractors commonly produce. It is not the output of one particular tool:
| What the extracted text contains | Tokens | vs clean |
|---|---|---|
| Line breaks every ~70 characters | 7,194 | +7.4% |
| + words split with a hyphen at line end | 7,273 | +8.5% |
| + ligature characters (fi, fl, ff) | 7,494 | +11.8% |
| + a page header and number every 50 lines | 7,650 | +14.2% |
| + double spaces from justified text | 8,749 | +30.6% |
Each row is small on its own, and each has a simple cause in the tokenizer.
Line breaks. The tokenizer stores a space plus a common word as one token: " the" is one token. A newline doesn't merge that way, so "\nthe" is two. Every one of the 682 line breaks costs about one extra token. You don't need a PDF to see this: the GPL-3 file as it ships in Linux distributions, wrapped by hand at about 72 characters, is 7,446 tokens, 11% more than the same text unwrapped.
Split words. "computer" is one token. "compu-\nter" is four: comp, u, -\n, ter. The 65 split words cost 79 tokens more than the same text with plain line breaks.
Ligatures. Typesetting software often merges "fi" or "fl" into one special character. "file" is one token. With the ligature it's two, because the tokenizer has rarely seen that character inside a word. Here 91 ligatures cost 221 extra tokens, about 2.4 each.
Page headers. A running title and page number cost about 12 tokens per page. That's the smallest effect here, and it's also repeated text that tells the model nothing.
Double spaces. Justified text stretches lines to the margin. Some extractors turn that stretched space into two or more space characters. Each extra space is one more token. In my simulation one inter-word space in four was doubled, which added 1,057 tokens, the biggest single row. Your extractor may produce fewer of these, or many more.
What it adds up to
All together, the same document goes from 6,701 to 8,749 tokens. The model reads 2,048 tokens of layout.
Suppose your tool sends a document this size 1,000 times a day. At gpt-5.6's list price of $2 per million input tokens (from the catalog snapshot of the LLM gateway I work on), that's $402 a month for clean text and $525 for raw extracted text: +$122.88 for nothing. claude-sonnet-5.5 has the same input price, so the gap is the same. On gemini-3.8-flash it's +$46, on gpt-5.6-mini +$12, on claude-haiku-5.5 +$6. I'm only counting the document, not the question or the answer.
The fix runs before the API call:
import re import unicodedata def clean_pdf_text(s): s = unicodedata.normalize("NFKC", s) # ligature characters -> plain letters s = re.sub(r"(\w)-\n(\w)", r"\1\2", s) # compu-\nter -> computer s = re.sub(r"(?<!\n)\n(?!\n)", " ", s) # line break inside a paragraph -> space s = re.sub(r"[ \t]+", " ", s) # runs of spaces -> one space s = re.sub(r"\n{3,}", "\n\n", s) return s.strip() print(clean_pdf_text("The modified program is a compu-\nter program,\nnot a docu-\nment.")) NFKC is a standard Unicode normalization that, among other things, turns a ligature character back into ordinary letters. The other lines join split words, turn single line breaks into spaces and collapse repeated spaces. A blank line stays, so paragraphs survive. With one extra pattern to remove the page header (that pattern depends on your document), the fully broken GPL text came back to 6,703 tokens, two more than the original.
What this doesn't solve
The cleaner guesses, and some guesses are wrong. A word that really has a hyphen, like "general-purpose", gets glued into "generalpurpose" when the line happens to break at that hyphen. Where a page break fell exactly between two paragraphs, my run merged them: 122 paragraphs became 119. Lists, tables and code lose their line structure completely, because to the regex a line break is a line break. NFKC also rewrites other characters: superscript ² becomes 2 and ½ becomes "1⁄2", which matters in technical and financial text.
It doesn't solve the hard PDF problems either. Text in two columns can come out interleaved line by line, and scanned pages contain no text at all until you run OCR. Removing extra tokens doesn't fix a jumbled reading order.
Finally, the artifacts here are simulated on one document and counted with one tokenizer. Claude and Gemini tokenize differently, and real extractors vary a lot, especially with spaces. Before you trust my percentages, count your own: run your extractor on a few real uploads, count tokens before and after cleaning, and read one cleaned page with your own eyes.

