Scanned or searchable? How to tell if a PDF has real text
Updated · Tested with PyMuPDF 2.2, Poppler 25.03, OCRmyPDF 17.14
In short
A searchable PDF stores letters; a scanned PDF stores a picture of each page. If you cannot select a word in a viewer, it is a scan. In code, a page whose extracted text is empty and which contains an image is a scan. OCR turns a scan into a searchable PDF by adding an invisible text layer.
Two PDFs can look identical on screen and be completely different inside. One holds text; the other holds a photograph of text. Everything you want to do with a document, searching it, copying from it, extracting data, depends on which one you have.
| Question | Searchable (text) PDF | Scanned PDF |
|---|---|---|
| Made by | Exporting or printing from a program | A scanner or a camera |
| Inside the file | Letters, fonts and positions | One picture per page |
| Select and search | Yes | No |
| Size of one page | A few kilobytes | Often 100 kilobytes or more |
| To get the text | Read it from the file | OCR |
A third kind is a scan that has been through OCR: the picture is still there, and an invisible layer of text sits on top of it. It behaves like a searchable PDF, and its text is only as good as the OCR was.
Check by hand
Open the file and try to select a single word. If the cursor draws a box across the page instead of highlighting words, it is a scan.
Check in code
A page with no text and at least one image is a scan. With PyMuPDF:
import pymupdf
def page_kinds(path):
kinds = []
with pymupdf.open(path) as doc:
for page in doc:
if page.get_text().strip():
kinds.append("text")
elif page.get_images():
kinds.append("scan")
else:
kinds.append("empty")
return kinds
for name in ["company-extract.pdf", "company-scan.pdf", "mixed-text-and-scan.pdf"]:
print(name, page_kinds(name))company-extract.pdf ['text']
company-scan.pdf ['scan']
mixed-text-and-scan.pdf ['text', 'scan']Check every page, not the first one. The third sample, mixed-text-and-scan.pdf, has a text page followed by a scanned one, which is common when a signed page is scanned and added to an exported document.
Check from the command line
The Poppler tools answer the same question. pdffonts lists the fonts in a file; a scan has none:
pdffonts company-scan.pdfname type encoding emb sub uni object ID
------------------------------------ ----------------- ---------------- --- --- --- ---------For company-extract.pdf the same command lists two fonts. And pdfimages -list shows the picture a scan is made of, with its resolution:
pdfimages -list company-scan.pdfpage num type width height color comp bpc enc interp object ID x-ppi y-ppi size ratio
1 0 image 2481 3508 rgb 3 8 image no 7 0 300 300 169K 0.7%One image the size of the whole page, at 300 dots per inch: a scan.
Make a scan searchable
OCRmyPDF adds a text layer to a scanned PDF and leaves the picture as it is. It uses the Tesseract OCR engine underneath.
ocrmypdf company-scan.pdf searchable.pdfAfterwards the check above reports ['text'], and pypdf reads the new file:
COMPANY EXTRACT
Company name Harbor Lane Logistics LtdThree options cover most real files:
| Option | When |
|---|---|
--skip-text | Mixed files: OCR the scanned pages, leave pages that already have text |
--force-ocr | The file has text, but it is wrong or gibberish |
-l heb+eng | The document is not in English; name its languages |
Without one of the first two, OCRmyPDF stops when it finds a page that already has text. That protects good text from being replaced by a worse reading.
Why it matters for extraction
- Cost and speed. Reading text from a file takes milliseconds. OCR takes around a second a page and more memory. Send only the pages that need it.
- Accuracy. Text read from the file is exact. OCR makes mistakes, more of them on poor scans; see how to improve OCR accuracy.
- Positions. Positions in a text PDF are exact, and positions from OCR are approximate.
How 100sands handles the two kinds
100sands reads only the first kind: PDFs and HTML files that contain text. It does not do OCR.
A PDF with no text on any page, such as company-scan.pdf, is refused with status 422 and a body of this shape:
{
"error": "NO_TEXT_IN_FILE",
"message": "This PDF has no text in it. It is probably a scan or a photo; only PDFs with text can be read."
}A file that mixes the two, like mixed-text-and-scan.pdf, is read. The text page comes back, and the scanned page comes back blank, with no error. The response has this shape:
{
"pages": 2,
"text": "COMPANY EXTRACT\nCompany name\tHarbor Lane Logistics Ltd\n...\f"
}Pages are separated by a form feed (\f), and nothing follows the one after the first page. If a blank page would matter to you, check your files page by page with the code above before you send them.