About Services Tools Blog Contact us

PDF Text with Scan Fallback

Gets the text out of a PDF by trying its built-in text, then scan-reading tools, then an image-reading model. Can join a folder of PDFs into one file.

  • Document Understanding & OCR
  • Cross-sector
  • Pipeline
  • Productised
  • Local/private
  • 2026

The problem

Some PDFs contain real text and some are photographs of pages. One extractor on its own either misses the scans or wastes time reading pages that were fine. A folder of supplier brochures also had to be opened one file at a time.

What it does

Each page is tried in order. The built-in text is kept when it is long enough. Pages with too little text go to a scan-reading tool, then to an image-reading model, then through a final tidy-up that is told not to add text. A folder run writes one combined file so the facts can be reused without retyping.

Outcomes

  • Text PDFs are read quickly and scanned ones still give text.
  • The chain stops at the first reader that returns enough text.
  • A folder of brochures becomes one text file.
  • The result is cached, so the same PDF is not read twice.

Simplified mockup

Interactive preview with sample data. Nothing is sent to a server.

Literature extract

12 literature PDFs March drop Kept when a reader returns at least 200 characters.
lumenbay-rooflights.pdf 18 pages

Trade brochure. The text layer is already long.

hale-depot-yard-gate.pdf 1 page scan

Photographed policy. The text layer is 38 characters.

Two files
Brochure and scan are queued.
Folder
12 literature PDFs, not opened yet.

Where the chain stopped

Floor 200 characters
PageText layerOn-device OCRVision modelKept
Rooflight brochure14,206not callednot calledText layer
Yard-gate scan381,104not calledOn-device OCR
Faded gasket sheet040860, then a tidyVision model

The tidy pass may only rephrase text it was given. It does not add a size, a temperature or a rule that was not on the page.

Same PDF, second open

Cache hit
FileFirst readOpened againReader stored
lumenbay-rooflights.pdf0.4 sNot read againText layer
hale-depot-yard-gate.pdf1.8 sNot read againOn-device OCR
nitrile-gasket-sheet.pdf6.2 sNot read againVision model
Stable names

lumenbay-rooflights.pdf
hale-depot-yard-gate.pdf
nitrile-gasket-sheet.pdf

Each file is stored once under a stable name. A later job reuses the text instead of calling OCR or the vision model again.

How it works

  1. Save the PDF under a stable name.
  2. Try its built-in text first and keep it when it is long enough.
  3. Read pages with too little text using the scan-reading tool on the Mac or Tesseract.
  4. Send page images to an image-reading model if the text is still thin.
  5. Run a final tidy-up that cleans the text and adds no facts.
  6. Write a folder of supplier PDFs out as one combined text file.

Pipeline

flowchart LR
  A["PDF"] --> B["LlamaIndex"]
  B --> C{"Enough text?"}
  C -->|Yes| D["Keep text"]
  C -->|No| E["macOS Vision"]
  E --> F{"Still thin?"}
  F -->|Yes| G["Qwen on Ollama"]
  F -->|No| D
  G --> H["Cursor cleanup"]