fix: nur die erste Person hatte im Tätigkeitenfeld etwas stehen
This commit is contained in:
1 parent
932585882e
commit
9f0e3cc8fc
1 file changed
+29
-18
+29
-18
@@ -171,9 +171,7 @@ def _fill_pdf_pages(
|
||||
"""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:
|
||||
@@ -201,7 +199,7 @@ def _fill_pdf_pages(
|
||||
if not formatted:
|
||||
continue
|
||||
|
||||
# Mehrzeilige Felder: insert_textbox mit Zeilenumbruch
|
||||
# Mehrzeilige Felder: Zeilenweise per insert_text schreiben
|
||||
if m.pdf_field in MULTILINE_FIELDS:
|
||||
# Doppelte Leerzeilen entfernen
|
||||
clean_text = "\n".join(
|
||||
@@ -210,21 +208,34 @@ def _fill_pdf_pages(
|
||||
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,
|
||||
)
|
||||
# Zeilenweise mit automatischem Umbruch schreiben
|
||||
lines = clean_text.split("\n")
|
||||
line_spacing = fontsize * 1.2 # Zeilenabstand
|
||||
y = rect.y0 + fontsize # Startposition (unterhalb Marker-Oberkante)
|
||||
|
||||
for line in lines:
|
||||
# Wort-Umbruch: Zeile in Stücke passend zur Textbox-Breite aufteilen
|
||||
max_width = TEXTBOX_WIDTH_PT
|
||||
words = line.split(" ")
|
||||
current_line = ""
|
||||
for word in words:
|
||||
test_line = current_line + (" " if current_line else "") + word
|
||||
text_width = fitz.get_text_length(test_line, fontname="helv", fontsize=fontsize)
|
||||
if text_width <= max_width or not current_line:
|
||||
current_line = test_line
|
||||
else:
|
||||
page.insert_text(
|
||||
(rect.x0, y), current_line,
|
||||
fontname="helv", fontsize=fontsize,
|
||||
)
|
||||
y += line_spacing
|
||||
current_line = word
|
||||
if current_line:
|
||||
page.insert_text(
|
||||
(rect.x0, y), current_line,
|
||||
fontname="helv", fontsize=fontsize,
|
||||
)
|
||||
y += line_spacing
|
||||
else:
|
||||
page.insert_text(
|
||||
rect.bl,
|
||||
|
||||
Reference in new issue
Block a user