Skip to content

Free Local OCR for Long PDFs — Baidu's Unlimited-OCR, Step by Step

Baidu open-sourced Unlimited-OCR: a 3B model that turns long PDFs into structured text, free, MIT-licensed, running on a laptop. The exact working commands, including the prompt gotcha.

Free Local OCR for Long PDFs — Baidu’s Unlimited-OCR, Step by Step

Paid OCR APIs charge you per page. Baidu just made that feel silly for a lot of everyday work: Unlimited-OCR is a free, MIT-licensed, open-weights model (2.4M+ downloads a month on Hugging Face) that reads document pages — dense text, tables, even LaTeX math — and writes them back out as structured text. On your machine. No API key, no per-page bill.

This guide is the exact path we ran on a MacBook, including the one prompt gotcha that makes most people think the model is broken. At the end: what it is genuinely good at, what it is not, and how to clean the output.

Why this model is different (in one paragraph)

Most OCR models choke on long documents because the memory cost balloons with every page. Unlimited-OCR is a 3-billion-parameter mixture-of-experts model — only about 500 million parameters fire per token — and its encoder compresses a full page image down to roughly 256 visual tokens. The result: it holds long documents steady (reports cite dozens of pages per pass) instead of running out of memory, and the whole thing fits on a single mid-range GPU — or, quantized, on a laptop. That memory behavior is the “unlimited” in the name. (Scope check: this is “long documents,” not “any document in one shot” — keep expectations honest.)

Step 1 — Install the pieces (macOS)

brew install ollama poppler
ollama serve   # leave this running in one terminal

Ollama runs the model; poppler gives you pdftoppm, which turns PDF pages into images the model can read.

Step 2 — Pull the model (quantized, laptop-sized)

The official weights are at baidu/Unlimited-OCR. For laptops, the community GGUF build runs directly in Ollama — 2.8 GB including the vision projector:

ollama pull hf.co/sahilchachra/Unlimited-OCR-GGUF:Q4_K_M
ollama cp hf.co/sahilchachra/Unlimited-OCR-GGUF:Q4_K_M unlimited-ocr   # short alias

Step 3 — Turn your PDF into page images

Grab any PDF — we used the famous “Attention Is All You Need” paper from arXiv:

curl -sL "https://arxiv.org/pdf/1706.03762" -o attention.pdf
pdftoppm -png -r 100 -f 1 -l 3 attention.pdf page   # pages 1–3 → page-01.png…

Step 4 — OCR a page (and the gotcha that matters)

ollama run unlimited-ocr "Free OCR." ./page-01.png

The gotcha: the prompt text matters. "Free OCR." is the phrase this model was trained on, and it works. If you ask it to “convert the document to markdown” on the GGUF build, you get an empty response and conclude the model is broken. It is not — you just used the wrong prompt. (This one line cost us twenty minutes; now it costs you zero.)

On our base MacBook each page took 5–12 seconds, streaming out structured text like:

title [342, 187, 656, 210]Attention Is All You Need
text  [232, 572, 767, 660]based on attention mechanisms, dispensing
with recurrence and convolutions entirely...

Notice what it is doing: not just reading the words, but labeling each block (title, text, page_footnote) with its position on the page. It even preserved the LaTeX math on page 2. That layout awareness is what separates document-parsing models from plain text scrapers.

Step 5 — Batch the whole document and clean the output

Loop the pages into one file, then strip the layout tags if you just want clean text:

for p in page-*.png; do ollama run unlimited-ocr "Free OCR." "$p" >> doc.txt; done
sed -E 's/^[a-z_]+ \[[0-9, ]+\]//' doc.txt > doc-clean.txt

The first command is your “free OCR pipeline” — every page, sequentially, zero API calls. The sed line removes the text [x, y, w, h] prefixes and leaves readable prose. Keep both files: the tagged version knows where everything was, which is gold if you later want to rebuild tables or extract only headings.

Pipelines like this are a hireable skill

Turning a raw model into a working document pipeline is exactly the kind of project DeployU teaches — hands-on, on real cloud infrastructure.

Got an NVIDIA GPU (or a free Colab)?

The full-precision model is stronger than the laptop quant. On any machine with a mid-range NVIDIA GPU — including a free Google Colab T4 — run the official weights with vLLM or Transformers straight from the model card, which ships ready-to-paste snippets for both. Same model, same prompts, more accuracy.

What it is good at — and honest limits

Good at: dense printed text, academic papers, multi-column layouts, tables, math notation, and long documents that make normal OCR fall over. And obviously: anything where “free and local” beats “upload my documents to someone’s API.”

Honest limits: the laptop version is a 4-bit quantization — expect occasional dropped characters versus the full model. Output is structured text, not a polished Word document — budget one cleanup pass. And accuracy on handwriting or low-quality scans is something you should test on your documents before trusting it. The right mental model: a very capable free reading assistant, not a certified transcription service.

The bigger lesson

A year ago this capability was an enterprise API with a per-page invoice. Today it is an MIT-licensed download that runs where your documents already live. The skill worth practicing is not this one model — it is the pattern: find the open model, verify the run path, build the small pipeline around it. That pattern keeps paying you every month a new model drops.

Build AI pipelines on real infrastructure

DeployU courses take you from “it runs on my laptop” to deployed, production-grade AI systems — on real AWS accounts.