New Tool Radar

AI PDF

How to Check Whether a PDF Has an Extractable Text Layer with pdftotext

Run pdftotext on a PDF and count the extracted words per page to find pages with no text layer.

Schematic with three steps: Extract the text; Count words page by page; Decide what each empty page means.

A PDF that looks like text may only contain images of text. pdftotext extracts the embedded text layer when one exists, so an empty or near-empty output tells you the page is a scan and needs OCR before you can search, copy, or quote from it.

What you need

  • poppler-utils installed, which provides pdftotext
  • A PDF to test
  • A way to count words, such as wc -w

Step 1: Extract the text

Run pdftotext file.pdf out.txt and open out.txt. A normal text page produces hundreds of words; a scanned page produces nothing.

Step 2: Count words page by page

Run pdftotext -f 2 -l 2 file.pdf page2.txt for each page you care about, then count the words in each output file.

Step 3: Decide what each empty page means

Open each page with no extracted text and look at it. A blank page is fine; a page full of visible text with no extracted text is a scan that needs OCR.

Worked example: synthetic text-layer check on a 3-page report

The table below is a synthetic example. It shows the expected result of checking a text layer; no extraction was run.

Page Extracted words Verdict
Page 1 412 Has a text layer
Page 2 0 Scanned image, needs OCR
Page 3 388 Has a text layer
Total 800 2 of 3 pages extractable

Expected result (UNTESTED). pages 1 and 3 extract cleanly (412 and 388 words) while page 2 extracts nothing, so page 2 is a scanned image and the document is only partly searchable. OCR page 2 before quoting from it. This check was not run live; the table shows the expected result for the synthetic example.

Limits

  • An empty output can mean a blank page as well as a scanned page, so always look at the page before deciding.
  • pdftotext extracts the text layer as stored, so garbled or out-of-order output does not prove the page is a scan.
  • Password-protected PDFs must be unlocked before pdftotext can read them.

Sources

See all