Coders In Hoods
  • Courses
  • Roles
  • Blog
  • Setup

Coders In Hoods AI Academy

Every course is free. Sign in to start, and your progress, quiz scores and bookmarks follow you.

AI Academy

  • Courses
  • Paths
  • Setup guides
  • How we teach

Role roadmaps

  • AI Engineer
  • Forward Deployed Engineer
  • Machine Learning Engineer
  • All roles

Coders In Hoods

  • The agency
  • Coaching for teams
  • Blog
  • LinkedIn
  • X (Twitter)

Contact

codersinhoods@gmail.com

© Coders In Hoods · since 2019

Setup guides

Setup guide · Tools and services

OCR and PDF parsing: Tesseract and Docling

Tesseract installed with its English language data and callable from Python through pytesseract, and Docling converting a PDF to Markdown in a uv project, each checked with a one-command smoke test.

20 min Updated 2026-10-31

Scanned deeds and leases have no usable text layer, so an ingestion pipeline has to read the pixels. The document-ingestion exercises compare two local tools against a vision model. Tesseract is the classic open-source OCR engine: fast, small and line-by-line. Docling is IBM's open-source document converter: it runs layout and table models to turn a whole PDF into Markdown or JSON, with OCR for the scanned parts. Install both once here.

Before you start

  • macOS, Linux or Windows, with Python and uv.
  • Tesseract needs about 50 MB. Docling is much bigger, because it depends on PyTorch: plan for about 1 GB of packages on macOS and Windows, and the same on Linux if you use the CPU-only index in step 3 (otherwise about 3.5 GB, mostly CUDA libraries you don't need). The first conversion also downloads about 500 MB of models.
  • 8 GB of RAM is enough for one page at a time.

1. Install Tesseract

macOS

brew install tesseract

The formula includes the English (eng) and orientation (osd) language data. For other languages, run brew install tesseract-lang.

Ubuntu and Debian

sudo apt install tesseract-ocr tesseract-ocr-eng

Windows

Download the current 64-bit installer (tesseract-ocr-w64-setup-…exe) from the UB Mannheim wiki and run it. English is always installed. The installer doesn't add Tesseract to PATH, so add the install folder yourself (usually C:\Program Files\Tesseract-OCR), then open a new terminal.

Check the binary

tesseract --version
tesseract --list-langs

The first prints tesseract 5.x.x and its libraries; the second must list eng.

2. Use it from Python

uv init ocr-smoke
cd ocr-smoke
uv add pytesseract pillow

pytesseract is a thin wrapper: it calls the tesseract binary you just installed, so it needs that binary on PATH. Save a test that draws text into an image and reads it back:

ocr_smoke.py
from PIL import Image, ImageDraw, ImageFont
import pytesseract
 
# On Windows without PATH set, point at the binary instead:
# pytesseract.pytesseract.tesseract_cmd = r"C:\Program Files\Tesseract-OCR\tesseract.exe"
 
image = Image.new("RGB", (900, 120), "white")
font = ImageFont.load_default(size=48)
ImageDraw.Draw(image).text((20, 30), "Title number ZZ123456", fill="black", font=font)
 
print("Tesseract", pytesseract.get_tesseract_version())
print(pytesseract.image_to_string(image).strip())
uv run ocr_smoke.py

Expected output:

Tesseract 5.5.1
Title number ZZ123456

The version is whatever your package manager installed. Real scans are harder than this: Tesseract wants clean, upright text at around 300 DPI, which is why the exercises also try Docling and a vision model.

3. Install Docling

In a separate project, so PyTorch doesn't slow down the small one:

uv init docling-smoke
cd docling-smoke

On Linux only, first add PyTorch's CPU index to pyproject.toml. Without it, uv installs the default Linux build of PyTorch with about 2.5 GB of CUDA libraries. macOS and Windows already get CPU builds from PyPI.

pyproject.toml
[[tool.uv.index]]
name = "pytorch-cpu"
url = "https://download.pytorch.org/whl/cpu"
explicit = true
 
[tool.uv.sources]
torch = [{ index = "pytorch-cpu" }]

Then, on every OS:

uv add docling

Run Hugging Face models on CPU explains the index settings.

4. Convert a PDF with Docling

uv run docling https://arxiv.org/pdf/2408.09869 --output out

This converts the Docling technical report to Markdown in out/2408.md (Docling names the file after the URL's last segment, up to the first dot). The first run is slow: Docling downloads its layout and table-structure models from Hugging Face (about 500 MB, into the Hugging Face cache) before it converts anything. On a recent laptop the first run takes one to two minutes and later runs much less. To download the models ahead of time, for a train or a flight, run uv run docling-tools models download.

The same from Python:

convert.py
from docling.document_converter import DocumentConverter
 
converter = DocumentConverter()
doc = converter.convert("https://arxiv.org/pdf/2408.09869").document
print(doc.export_to_markdown()[:500])

By default Docling uses its own OCR engine for scanned regions. To compare it with Tesseract on the same page, run uv run docling scan.pdf --ocr-engine tesseract --output out.

Check it works

tesseract --list-langs && uv run docling https://arxiv.org/pdf/2408.09869 --output out && grep -m1 '^## ' out/2408.md

Expected: a list that includes eng, a log line Finished converting document 2408.09869 in … sec, then the first heading of the Markdown: ## Docling Technical Report.

Troubleshooting

TesseractNotFoundError from pytesseract. The binary isn't on PATH for the shell running uv. Open a new terminal after installing, or set pytesseract.pytesseract.tesseract_cmd to the full path, as in the comment above.

Failed loading language 'eng'. The language data is missing or Tesseract is looking in the wrong folder. Install tesseract-ocr-eng (Linux) or reinstall (macOS, Windows). If you set TESSDATA_PREFIX, it must point at the tessdata folder and end with a slash.

uv add docling downloads gigabytes on Linux. The CPU index from step 3 is missing or misspelt. Add it, then run uv lock --upgrade-package torch and uv sync.

The first Docling run hangs or fails offline. It's downloading models. Let it finish once on a good connection, or run docling-tools models download beforehand.

Going further

  • Run Hugging Face models on CPU, for the PyTorch and cache details Docling relies on
  • Python with uv

Sources

  • Tesseract installationDocs · Tesseract OCRPackages for each OS, the language-data packages, and the UB Mannheim installer for Windows.
  • Tesseract at UB MannheimDocs · UB MannheimThe Windows installer, and why it no longer adds Tesseract to `PATH` for you.
  • pytesseractDocsThe Python wrapper; `image_to_string`, `get_tesseract_version` and `tesseract_cmd`.
  • Docling installationDocs · Docling Project`uv add docling`, the CPU-only PyTorch index for Linux, and the optional OCR engines.
  • Docling advanced optionsDocs · Docling ProjectModels download on first use; `docling-tools models download` prefetches them.

Exercises that use this

  • Run a four-way parser bake-offDocument Ingestion Pipelines · Parsing: text layers to vision models
  • Measure two-reader agreement on handwritingDocument Ingestion Pipelines · Tables, plans and handwriting

On this page

  • Before you start
  • 1. Install Tesseract
  • macOS
  • Ubuntu and Debian
  • Windows
  • Check the binary
  • 2. Use it from Python
  • 3. Install Docling
  • 4. Convert a PDF with Docling
  • Check it works
  • Troubleshooting
  • Going further
  • Sources
  • Exercises that use this