Does converting a PDF to Markdown save tokens? I measured three PDFs
Markdown cut tokens by 7% to 15% on three public PDFs, but most of that was extra spaces, header cleanup did little, and a two-column file came out scrambled.
Several older posts on this site say that converting a PDF to Markdown saves hours of tuning, drops the noise a model never needed, or cuts 15% to 30% of the tokens. I wrote those claims without measuring anything. This post is the measurement, and it changed what I think the converter is good for.
The short version: Markdown did cut tokens, by 7% to 15% on three public PDFs. Nearly all of that came from extra spaces in the plain-text baseline, not from removing junk. Header and footer cleanup removed something on one of the three files. And on the two-column PDF, the page I read came out with its columns mixed together.
How I tested it
I used three public PDFs: Attention Is All You Need, the NIST AI Risk Management Framework 1.0, and the IRS Instructions for Form 1040 (the 2025 edition dated February 25, 2026, 126 pages).
On November 30, 2026, I ran the source file of PDFShore's PDF to Markdown converter in Node with pdf.js 5.7.284 and gpt-tokenizer 3.4.0, counting with the o200k_base encoding. Only the module and worker paths were adapted. OCR was off. No page in these files has fewer than 40 characters of text, which is the point where Auto OCR would start anyway. The baseline is the text the Token Counter extracts from the same file.
What the converter did to the token count
| Document | Pages | Token Counter text | Markdown, no cleanup | Markdown, panel defaults |
|---|---|---|---|---|
| Attention Is All You Need | 15 | 10,621 | 9,701 (-8.7%) | 9,776 (-8.0%) |
| NIST AI RMF 1.0 | 48 | 21,419 | 19,985 (-6.7%) | 19,587 (-8.6%) |
| IRS Form 1040 instructions (2025) | 126 | 245,481 | 208,450 (-15.1%) | 209,080 (-14.8%) |
Panel defaults are Balanced cleanup plus page headings. I also ran cl100k_base, and every percentage landed within 0.2 points of the o200k figure. Every document got smaller, so the claim holds in a modest form. What matters is where the drop came from.
Most of the saving is extra spaces
The Token Counter joins every text fragment pdf.js returns with a space. Between words, pdf.js often returns a fragment that is only a space: 19% of the fragments in the Attention paper, 21% in NIST and 35% in the IRS file. Joined with spaces, each one becomes a run of two or more spaces: 930 in the Attention text, 982 in NIST and 37,674 in the IRS file. A tokenizer counts those. I took the Counter's own text, replaced runs of spaces and tabs with a single space, and kept every line break. Tokens fell by -8.8%, -4.6%, and -15.3%.
Compare that with the Markdown column above. On Attention and the IRS file, spaces alone explain all of the drop. On NIST they explain 4.6 of the 6.7 points. The other 2.1 points come from the converter's line handling, such as joining wrapped lines and dropping page-number lines. I did not split those further.
That means the saving is partly a quirk of the baseline. If you already paste text with single spaces, you would save much less than the table suggests. It also means the Token Counter runs high. I added a note about that to its FAQ and left the count itself unchanged, because several earlier posts quote numbers measured with it.
Header and footer cleanup did less than I expected
The converter removes a line only when the same text is the first, second, last or second-to-last line on at least 60% of the pages. That produced three different outcomes.
- Attention: 0 lines removed. No line repeats on 60% of the pages.
- NIST:43 lines removed, the header “NIST AI 100-1 AI RMF 1.0” on 43 of 48 pages. That is 638 tokens, 3.2% of the Markdown without cleanup.
- IRS:0 lines removed. The footer “Need more information or forms? Visit IRS.gov.” appears on 70 of the 126 pages, and the page number sits on the same line, after the text on 35 pages and before it on 24 (the other 11 look different). The text is never identical on 60% of the pages, so it stays. That is 12 tokens a page, about 840 tokens or 0.4% of the output.
Two smaller settings are worth knowing. Aggressive saved 35 tokens over Balanced on Attention, 9 on NIST and 300 on the IRS file, all under 0.5%, and it drops one- and two-character lines, which can flatten lists. I would leave Balanced on. Page headings cost 5 tokens per page in all three files (75, 240 and 630 tokens), which is cheap if you cite page numbers.
The two-column PDF came out scrambled
The IRS instructions run in two columns. On page 21, the Token Counter's text reads “Temporary absences by you or the other person for special circumstances, such as school, vacation, business...”. In the Markdown, the same line reads “Temporary absences by you with you all year as a member of your household) but you and”. The converter groups fragments by vertical position, so text from both columns can land on one line.
To put a number on it, I compared four-word sequences between the Counter's text and the Markdown. 93.1% of the Attention sequences also appear in the Markdown, 87.7% for NIST and 66.6% for the IRS file. In the IRS Markdown, 37.3% of the sequences do not appear in the Counter's text at all. This is not a quality score. Joining lines, removing hyphens and dropping headers legitimately change some sequences. But a 15% saving on a document where more than a third of the Markdown's sequences are new is not a free saving.
A bug I found along the way
My first run showed a real defect. When a line ended in a hyphen, the converter always glued the two halves together. That is right for “recommenda-tion” and wrong for “English-to-German”, which came out as “Englishto-German”. I changed it to look at the rest of the document. If the joined word appears elsewhere, it joins. If the hyphenated form appears elsewhere, it keeps the hyphen. If both halves are words on their own, it keeps the hyphen. The numbers above come from the fixed version. The fix moved the token count by 2 on Attention and 1 on NIST.
It is not perfect. “Sequence-aligned” (twice in the Attention paper) and “off-label” (once in the NIST framework) still come out as “sequencealigned” and “offlabel”. I checked those by hand. I did not audit the roughly 875 line-end hyphen splits in the IRS file, so I cannot give you an error rate.
What I did not test
- Model answers, retrieval quality, or any provider bill. This is only about token counts and text order.
- Scanned PDFs and OCR output.
- Other tokenizers beyond the two OpenAI encodings, and languages other than English.
- More than three documents. They are all digital PDFs, so treat the percentages as examples.
What I would do with this
- Count your own file twice, once in the Token Counter and once after conversion. Your baseline may not carry the extra spaces.
- Do not count on cleanup to find footers that carry a page number. The converter shows how many lines it removed, so check that.
- Keep Balanced. Aggressive is not worth the lost short lines.
- On multi-column PDFs, read a page of the Markdown before trusting it. On the page I checked, the Counter's text kept the order better.
The PDF to Markdown converter and the Token Counter both run in your browser, so the file stays on your device. For page-level counts see how many tokens are in one PDF page, and for what to do next with a long document, the RAG preparation guide.
Source checksums for reproducing the test
Public files can change at the same URL. SHA-256 values of the downloaded originals:
Attention: bdfaa68d8984f0dc02beaca527b76f207d99b666d31d1da728ee0728182df697
NIST: 7576edb531d9848825814ee88e28b1795d3a84b435b4b797d3670eafdc4a89f1
IRS: 482e9c487c608f1bbeaceef35bc3c0933e8b35443cfff447e4279d590468364a