# -*- coding: utf-8 -*- """Measure where the first real employment evidence starts on page one (review finding F18). Usage: python resume_builder/helpers/page_metrics.py [more.pdf ...] Requires pdftotext (ships with MiKTeX). The review reported ~50-55% for four packages. This reproduces that measurement from the compiled PDF so a change can be checked rather than asserted. The percentage is a diagnostic, never a target: no pixel goal, no forced page-two filling. """ import re import shutil import subprocess import sys import tempfile from pathlib import Path HEADINGS = ("professional experience", "berufserfahrung", "experience") def measure(pdf: Path) -> dict: executable = shutil.which("pdftotext") if not executable: raise RuntimeError("pdftotext is required on PATH (Poppler or MiKTeX)") with tempfile.TemporaryDirectory() as work: out = Path(work) / "bbox.xml" subprocess.run([executable, "-bbox", "-f", "1", "-l", "1", str(pdf), str(out)], capture_output=True, check=True) xml = out.read_text(encoding="utf-8", errors="replace") page = re.search(r'([^<]*)', xml)] rows = {} for y, text in words: rows.setdefault(round(y, 1), []).append(text) first_y = next((y for y, row in sorted(rows.items()) if " ".join(row).strip() in HEADINGS), None) lines = len(rows) return { "height": height, "experience_y": first_y, "experience_pct": round(100 * first_y / height, 1) if first_y else None, "page1_text_lines": lines, "page1_words": len(words), } if __name__ == "__main__": for argument in sys.argv[1:]: pdf = Path(argument) data = measure(pdf) pct = data["experience_pct"] print(f"{pdf.parent.name:<34} experience starts at " f"{pct if pct is not None else '?':>5}% of page 1 | " f"{data['page1_text_lines']:>3} text lines, {data['page1_words']:>4} words")