MadsLorentzen/ai-job-search · error · VerificationError

pdfinfo output did not contain a page count

Error message

pdfinfo output did not contain a page count

What it means

This error is raised by parse_page_count() when the output captured from the `pdfinfo` utility does not contain a line matching `Pages: <number>`. The library relies on that line to determine the PDF's page count, so if pdfinfo produced no parseable Pages field (or was not actually pdfinfo output), verification cannot continue.

Source

Thrown at tools/verify_pdf.py:46

            errors="replace",
        ).stdout
    except FileNotFoundError as exc:
        raise VerificationError(
            f"required command '{command[0]}' was not found. "
            "Install pypdf (`pip install pypdf`) or poppler-utils "
            "(macOS: brew install poppler, Debian/Ubuntu: apt install poppler-utils, "
            "Windows: choco install poppler)"
        ) from exc
    except subprocess.CalledProcessError as exc:
        detail = (exc.stderr or "").strip() or (exc.stdout or "").strip()
        detail = detail or "command failed"
        raise VerificationError(f"{command[0]} could not read the PDF: {detail}") from exc


def parse_page_count(pdfinfo_output):
    match = re.search(r"^Pages:\s+(\d+)\s*$", pdfinfo_output, re.MULTILINE)
    if not match:
        raise VerificationError("pdfinfo output did not contain a page count")
    return int(match.group(1))


def normalize_text(text):
    return " ".join(text.split())


def _extract_pypdf(pdf_path):
    """Return (text, pages) or None if pypdf is unavailable, raises, or yields no text."""
    try:
        from pypdf import PdfReader
    except ImportError:
        return None
    try:
        reader = PdfReader(str(pdf_path))
        pages = len(reader.pages)
        text = "\n".join((page.extract_text() or "") for page in reader.pages)
    except Exception:

View on GitHub (pinned to 79cd383e58)

Solutions

  1. Check that poppler-utils is installed and `pdfinfo file.pdf` manually prints a `Pages:` line
  2. Ensure the string passed to parse_page_count is the captured stdout of pdfinfo, not stderr or another tool's output
  3. If the PDF is corrupt, regenerate or verify it before calling parse_page_count
  4. Upgrade/downgrade poppler-utils if its output format differs, or loosen the regex to tolerate varying whitespace/case

Example fix

// before
pages = parse_page_count(subprocess.run(["pdftotext", path], capture_output=True).stdout)
// after
pages = parse_page_count(subprocess.run(["pdfinfo", path], capture_output=True, text=True).stdout)
Defensive patterns

Strategy: validation

Validate before calling

import re
def pdfinfo_output_looks_valid(out: str) -> bool:
    return re.search(r'^Pages:\s+\d+\s*$', out, re.MULTILINE) is not None

Try / catch

try:
    pages = parse_page_count(out)
except VerificationError as e:
    raise RuntimeError(f'pdfinfo unusable, raw output: {out!r}') from e

Prevention

When it happens

Trigger: Calling parse_page_count() with a string that lacks a `Pages: N` line: empty output, localized pdfinfo output, an error banner from poppler, or output from a different tool. Indirectly hit via verify_pdf() when the pdfinfo path in extract_text_layer() returns malformed/unexpected stdout or stderr text.

Common situations: pdfinfo not installed or old/new poppler versions printing differently; shell wrappers or containers mangling output; passing a corrupted PDF so pdfinfo prints an error instead of metadata; passing pdftotext output instead of pdfinfo output.

Related errors


AI-assisted analysis of MadsLorentzen/ai-job-search@79cd383e58 (2026-08-27). Data as JSON: /api/errors/d557b7042049a536. Report an issue: GitHub.