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
+13
-8
No files matched your search
+13
-8
@@ -195,10 +195,10 @@ def _fill_pdf_pages(
|
|||||||
# Zeilenweise mit automatischem Umbruch schreiben
|
# Zeilenweise mit automatischem Umbruch schreiben
|
||||||
lines = clean_text.split("\n")
|
lines = clean_text.split("\n")
|
||||||
line_spacing = fontsize * 1.2 # Zeilenabstand
|
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:
|
for line in lines:
|
||||||
# Wort-Umbruch: Zeile in Stücke passend zur Textbox-Breite aufteilen
|
|
||||||
max_width = TEXTBOX_WIDTH_PT
|
max_width = TEXTBOX_WIDTH_PT
|
||||||
words = line.split(" ")
|
words = line.split(" ")
|
||||||
current_line = ""
|
current_line = ""
|
||||||
@@ -208,21 +208,26 @@ def _fill_pdf_pages(
|
|||||||
if text_width <= max_width or not current_line:
|
if text_width <= max_width or not current_line:
|
||||||
current_line = test_line
|
current_line = test_line
|
||||||
else:
|
else:
|
||||||
page.insert_text(
|
output_lines.append(current_line)
|
||||||
(rect.x0, y), current_line,
|
|
||||||
fontname="helv", fontsize=fontsize,
|
|
||||||
)
|
|
||||||
y += line_spacing
|
|
||||||
current_line = word
|
current_line = word
|
||||||
if current_line:
|
if current_line:
|
||||||
|
output_lines.append(current_line)
|
||||||
|
|
||||||
|
# Textblock oben beginnend schreiben
|
||||||
|
y = rect.y0 + fontsize
|
||||||
|
|
||||||
|
for current_line in output_lines:
|
||||||
page.insert_text(
|
page.insert_text(
|
||||||
(rect.x0, y), current_line,
|
(rect.x0, y), current_line,
|
||||||
fontname="helv", fontsize=fontsize,
|
fontname="helv", fontsize=fontsize,
|
||||||
)
|
)
|
||||||
y += line_spacing
|
y += line_spacing
|
||||||
else:
|
else:
|
||||||
|
# Einzeilige Felder: vertikal zentriert platzieren
|
||||||
|
mid_y = (rect.y0 + rect.y1) / 2
|
||||||
|
baseline_y = mid_y + fontsize * 0.35
|
||||||
page.insert_text(
|
page.insert_text(
|
||||||
rect.bl,
|
(rect.x0, baseline_y),
|
||||||
formatted,
|
formatted,
|
||||||
fontname="helv",
|
fontname="helv",
|
||||||
fontsize=fontsize,
|
fontsize=fontsize,
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
Reference in new issue
Block a user