Vergrößere alle Textfelder auf das gesamte Formularfeld und zeichne Text mittig.
This commit is contained in:
1 parent
2247c42e81
commit
b498af39d9
3 files changed
+18
-13
No files matched your search
+18
-13
@@ -195,10 +195,10 @@ def _fill_pdf_pages(
|
||||
# Zeilenweise mit automatischem Umbruch schreiben
|
||||
lines = clean_text.split("\n")
|
||||
line_spacing = fontsize * 1.2 # Zeilenabstand
|
||||
y = rect.y0 + fontsize # Startposition (unterhalb Marker-Oberkante)
|
||||
|
||||
# Zuerst alle Ausgabezeilen sammeln, um Gesamthöhe zu berechnen
|
||||
output_lines: list[str] = []
|
||||
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 = ""
|
||||
@@ -208,21 +208,26 @@ def _fill_pdf_pages(
|
||||
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
|
||||
output_lines.append(current_line)
|
||||
current_line = word
|
||||
if current_line:
|
||||
page.insert_text(
|
||||
(rect.x0, y), current_line,
|
||||
fontname="helv", fontsize=fontsize,
|
||||
)
|
||||
y += line_spacing
|
||||
output_lines.append(current_line)
|
||||
|
||||
# Textblock oben beginnend schreiben
|
||||
y = rect.y0 + fontsize
|
||||
|
||||
for current_line in output_lines:
|
||||
page.insert_text(
|
||||
(rect.x0, y), current_line,
|
||||
fontname="helv", fontsize=fontsize,
|
||||
)
|
||||
y += line_spacing
|
||||
else:
|
||||
# Einzeilige Felder: vertikal zentriert platzieren
|
||||
mid_y = (rect.y0 + rect.y1) / 2
|
||||
baseline_y = mid_y + fontsize * 0.35
|
||||
page.insert_text(
|
||||
rect.bl,
|
||||
(rect.x0, baseline_y),
|
||||
formatted,
|
||||
fontname="helv",
|
||||
fontsize=fontsize,
|
||||
|
||||
Reference in new issue
Block a user