Skip to content
MyDSHMy DSH Field Notes
中文
Independently maintained; not affiliated with DeepSeek. No association with mydsh.dev or other MyDSH sites.

Home/Workspace & files/Reading files & formats

Scanned PDFs have no text layer: you get nothing, not wrong text

After processing a batch of PDFs some entries look wrong or blank, and the first instinct is that the model misread them.

VerifiedVersion and environmentChecked 2026-11-14
Tool
pymupdf (PyMuPDF) with Python 3.13
Sample
100 synthetic PDFs, 20 with image only and no text layer
Checked
2026-11-14

Copyable command

python -c "import pymupdf,sys;d=pymupdf.open(sys.argv[1]);t=''.join(p.get_text() for p in d);print(len(t.strip()),'chars',sum(len(p.get_images(full=True)) for p in d),'images')" file.pdf

The conclusion first: a scan that yields nothing is not a failure, it never had readable text. Text in a PDF exists in two forms — a text layer of extractable characters, and an image of pixels. Scans only have the second.

Measured on two files, the difference is plain:

FilePagesExtractable charsEmbedded imagesReads as text?
PDF with a text layer1340Yes
Same page rendered to an image, wrapped in a PDF101No

Detection method, no model involved:

import pymupdf
d = pymupdf.open(path)
txt = "".join(p.get_text() for p in d)
print(len(txt.strip()), "chars", sum(len(p.get_images(full=True)) for p in d), "images")

Zero characters with one or more images means a scan. This check runs before the file reaches the model and saves a whole round.

Why check first

Handed a PDF with no text layer, the model has three options: say it cannot read it, invent something plausible, or fall back to OCR if the toolchain has it. The third is best; the first two cost you time to distinguish.

So the correct recipe is: list files with no text layer, report them separately, never skip silently and never let it guess. Cheaper than checking the output afterwards.

What to do

  1. Run the character-count check across the batch and pull out the zero cases into their own section.
  2. If OCR is available, run it; otherwise mark them 'read failed, no text layer' with filename and page count.
  3. Write it into the instruction: anything unreadable gets marked as failed, never inferred from the filename.

What counts as working

Check every line. All of them pass or the job is not done.

  • You can report both the character count and image count for a file
  • Scans are listed separately, not silently skipped
  • Nothing in the output was inferred from filenames

Where it fails

Symptom, cause, what to do — written in the order it actually happens.

SymptomCauseWhat to do
Every PDF returns 0 charactersThe whole batch is scans, or files are encrypted/corruptOpen one in a reader and check whether text is selectable; if it is, the extraction is wrong
Non-zero characters but garbageFonts not embedded, character mapping missing (common in older Chinese PDFs)Verify by hand; treat as untrusted rather than feeding it forward

Sources

Verified means measured here. Compiled means every line carries a source.