ouput pdf: text styling
This commit is contained in:
1 parent
e50f423304
commit
9bdd90c073
1 file changed
+35
-3
+35
-3
@@ -169,6 +169,12 @@ def _fill_pdf_pages(
|
||||
field_info: dict[str, dict],
|
||||
) -> None:
|
||||
"""Befüllt alle Template-Seiten: redacted _Field-Platzhalter und fügt echte Daten ein."""
|
||||
# Mehrzeilige Felder, die als Textbox (mit Zeilenumbruch) behandelt werden
|
||||
MULTILINE_FIELDS = {"Tätigkeiten_Field", "Dienstreisen_Field"}
|
||||
TEXTBOX_FONT_SCALE = 1 # Schriftgrößen-Faktor für Textboxen
|
||||
TEXTBOX_WIDTH_PT = 400 # Breite der Textbox in Punkt
|
||||
TEXTBOX_HEIGHT_PT = 120 # Höhe der Textbox in Punkt
|
||||
|
||||
for m in mapping:
|
||||
if m.pdf_field is None:
|
||||
continue
|
||||
@@ -188,12 +194,38 @@ def _fill_pdf_pages(
|
||||
value = _get_field_value(record, employee_name, m.source_field)
|
||||
formatted = _format_value(value, m.format)
|
||||
|
||||
# Platzhalter redacten
|
||||
# Platzhalter immer redacten, auch wenn kein Wert zum Einsetzen da ist
|
||||
page.add_redact_annot(rect)
|
||||
page.apply_redactions()
|
||||
|
||||
# Neuen Text einfügen
|
||||
if formatted:
|
||||
if not formatted:
|
||||
continue
|
||||
|
||||
# Mehrzeilige Felder: insert_textbox mit Zeilenumbruch
|
||||
if m.pdf_field in MULTILINE_FIELDS:
|
||||
# Doppelte Leerzeilen entfernen
|
||||
clean_text = "\n".join(
|
||||
line for line in formatted.split("\n") if line.strip()
|
||||
)
|
||||
if not clean_text:
|
||||
continue
|
||||
|
||||
# Rechteck für die Textbox: ausgehend vom Marker, nach rechts & unten erweitert
|
||||
textbox_rect = fitz.Rect(
|
||||
rect.x0, # links
|
||||
rect.y0, # oben
|
||||
rect.x0 + TEXTBOX_WIDTH_PT, # rechts
|
||||
rect.y0 + TEXTBOX_HEIGHT_PT, # unten
|
||||
)
|
||||
page.insert_textbox(
|
||||
textbox_rect,
|
||||
clean_text,
|
||||
fontname="helv",
|
||||
fontsize=fontsize * TEXTBOX_FONT_SCALE,
|
||||
lineheight=1.5,
|
||||
align=fitz.TEXT_ALIGN_LEFT,
|
||||
)
|
||||
else:
|
||||
page.insert_text(
|
||||
rect.bl,
|
||||
formatted,
|
||||
|
||||
Reference in new issue
Block a user