sdf
This commit is contained in:
39
dump_pdfplumber.py
Normal file
39
dump_pdfplumber.py
Normal file
@@ -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}")
|
||||
Reference in New Issue
Block a user