From af703b362928de72cdf38040fd76d7c35f02bf12 Mon Sep 17 00:00:00 2001 From: Andreas Knuth Date: Sat, 11 Jul 2026 13:51:36 -0500 Subject: [PATCH] sdf --- dump_pdfplumber.py | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 dump_pdfplumber.py diff --git a/dump_pdfplumber.py b/dump_pdfplumber.py new file mode 100644 index 0000000..89c747d --- /dev/null +++ b/dump_pdfplumber.py @@ -0,0 +1,39 @@ +#!/usr/bin/env python3 +""" +dump_pdfplumber.py - Zeigt, wie PDFPLUMBER (nicht pypdf) die Seiten ausgibt. +Wichtig: pdfplumber ordnet Text anders an als pypdf. + +Aufruf: + python3 dump_pdfplumber.py --pdf ~/data/S/"Sturgill, Garett 040126.pdf" +""" +import argparse +import pdfplumber + +ANCHOR_INFO = "BUYER INFORMATION SHEET" +ANCHOR_CA = "PROSPECTIVE BUYER AGREES TO KEEP AND HOLD CONFIDENTIAL" + +ap = argparse.ArgumentParser() +ap.add_argument("--pdf", required=True) +args = ap.parse_args() + +with pdfplumber.open(args.pdf) as pdf: + for i, page in enumerate(pdf.pages): + txt = page.extract_text() or "" + is_info = ANCHOR_INFO in txt + is_ca = ANCHOR_CA in txt.replace("\n", " ") + tag = "INFO" if is_info else ("CA" if is_ca else "andere") + if tag == "andere": + continue + print(f"\n{'='*70}") + print(f"=== SEITE {i+1} [{tag}] - extract_text() ===") + print('='*70) + for ln, line in enumerate(txt.splitlines(), 1): + print(f"{ln:3} | {line!r}") + + # Zusaetzlich: Woerter mit Position, um den Werte-Block zu lokalisieren + if is_info: + print(f"\n--- Woerter unterhalb von y=550 (wo die Werte stehen sollten) ---") + words = page.extract_words() + for w in words: + if w["top"] > 550: + print(f" top={w['top']:.0f} x0={w['x0']:.0f} {w['text']!r}") \ No newline at end of file