Resume Parser
← Back to blogBlog

How to tell if a PDF resume has a text layer before you parse it

A scanned resume is a picture of text, and a parser without OCR has nothing to read. Three quick ways to check a PDF for a text layer, in the shell and in Python.

Herizon

A PDF resume has a text layer when you can select and copy its words in a PDF viewer. If you can't, the file is a scanned image, and a parser without OCR gets no text from it. The fastest programmatic check is to extract the text and count the characters: a one-page resume with a text layer gives hundreds or thousands of characters, a scan gives close to zero.

This matters for our API because it reads the text layer only. A PDF without one returns 422 parse_failed, which is not charged, but your user still waits for nothing. Checking first lets you tell the candidate right away. The API docs list the error codes.

Why some PDFs have no text

A PDF made by "Save as PDF" or "Export to PDF" in Word, Google Docs, Pages, Canva or LaTeX stores each word as text with a font and a position. A PDF made by a scanner, a phone scanning app or "Print to PDF" from an image stores one picture per page. Some phone apps run OCR and add an invisible text layer on top of the picture; others don't. You can't tell from the file name or the size.

There is also a third case: PDFs that have text, but in a font with a broken character map, so copying gives you garbage symbols. These are rarer, and the check below catches most of them because the extracted text has very few letters.

Check 1: select the text

Open the file, press Ctrl+A or Cmd+A, and copy into a text editor. If the paste is empty or a few stray characters, there is no usable text layer. This is the check to give candidates in your upload form help text.

Check 2: pdftotext in the shell

Poppler ships pdftotext and pdffonts. On macOS install it with brew install poppler, on Debian and Ubuntu with apt install poppler-utils.

pdftotext -layout resume.pdf - | wc -c
pdffonts resume.pdf

The first command prints the character count of the extracted text. The second lists the fonts the PDF uses. A scanned PDF usually lists no fonts at all, since there is no text to draw.

Check 3: Python before upload

If your backend is in Python, pypdf can run the same check without system packages:

from pypdf import PdfReader

def has_text_layer(path: str, min_chars: int = 200) -> bool:
    reader = PdfReader(path)
    text = "".join(page.extract_text() or "" for page in reader.pages)
    letters = sum(ch.isalpha() for ch in text)
    return letters >= min_chars

Counting letters instead of all characters filters out PDFs that only contain page numbers, bullets or garbled symbols. 200 letters is a low bar: a name, a job title and a few bullet points pass it. Tune it on your own files.

What to do with a scanned resume

You have three options:

  1. Ask the candidate for the original file. Most scanned resumes were typed in a word processor first, so the candidate can export a proper PDF in a minute.
  2. Run OCR yourself before parsing. OCRmyPDF adds a text layer to a scanned PDF with ocrmypdf scan.pdf out.pdf. OCR quality depends on the scan, so check a few results before you automate it.
  3. Enter the data by hand for the few that remain.

For a careers form, option 1 at upload time is the cheapest. The candidate is still on the page, and the message can be specific: "This PDF looks like a scan. Please upload the PDF you exported from Word or Google Docs."

Where this fits

A text-layer check is one of several checks worth running before a resume reaches the parser. The PDF resume parser page explains what the API reads from a PDF, and our older post on converting PDFs into readable text explains why even a good text layer is only the start.

Questions

How do I know if a PDF is scanned?
Select all the text in a PDF viewer and paste it into a text editor. If nothing or only a few symbols come out, the PDF is a scanned image without a text layer.
Can Resume Parser read scanned PDFs?
No. The API reads the PDF text layer and has no OCR, so a scanned PDF returns 422 parse_failed. Failed parses are not charged.
How do I add a text layer to a scanned PDF?
Run OCR on it, for example with the open-source tool OCRmyPDF, or ask the candidate for the PDF exported from their word processor.

Want to try our parser?

Sign up with your email and get 50 free parses per month.

Get API key

Feedback

Send feedback

Tell us what went wrong or what you would like to see.

What is it about?

Sent with the address of this page. See the privacy policy.