[32788f42] Fix font encoding for PDF generation, compress empty slots in appointment list, adjust layout and checkbox positioning

This commit is contained in:
2026-03-21 19:23:31 +00:00
parent d3987ea20b
commit 1c98566e93
4 changed files with 143 additions and 63 deletions

View File

@@ -149,6 +149,7 @@ def get_calendly_events(api_token: str, start_time: str = None, end_time: str =
has_consent = False
questions_and_answers = item.get('questions_and_answers', [])
for q_a in questions_and_answers:
q_text = q_a.get('question', '').lower()
a_text = q_a.get('answer', '')
@@ -157,19 +158,13 @@ def get_calendly_events(api_token: str, start_time: str = None, end_time: str =
num_children = a_text
elif "nachricht" in q_text or "anmerkung" in q_text:
additional_notes = a_text
elif "schöne bilder" in q_text and "website veröffentlichen" in q_text:
if "ja, gerne" in a_text.lower():
elif "veröffentlichen" in q_text or "bilder" in q_text:
if "ja" in a_text.lower():
has_consent = True
# Construct the final string: "[☑] Name, X Kinder // HH:MM Uhr (Notes)"
# matching: Halime Türe, 1 Kind // 12:00 Uhr
final_text = ""
if has_consent:
# We use a placeholder character or string that we will handle in overlay_text_on_pdf
# because standard Helvetica doesn't support Unicode checkbox.
final_text += ""
final_text += f"{name}"
# Construct the final string: "Name, X Kinder // HH:MM Uhr ☑"
final_text = f"{name}"
if num_children:
final_text += f", {num_children}"
@@ -177,8 +172,12 @@ def get_calendly_events(api_token: str, start_time: str = None, end_time: str =
if additional_notes:
final_text += f" ({additional_notes})"
if has_consent:
final_text += ""
formatted_data.append(final_text)
logger.info(f"Processed {len(formatted_data)} invitees.")
return formatted_data
@@ -219,6 +218,13 @@ def overlay_text_on_pdf(base_pdf_path: str, output_pdf_path: str, texts: list):
# We need to process pairs of texts for each page
text_pairs = [texts[i:i+2] for i in range(0, len(texts), 2)]
# Load OpenSans font to support UTF-8 extended characters
from reportlab.pdfbase.ttfonts import TTFont
from reportlab.pdfbase import pdfmetrics
font_path = os.path.join(os.path.dirname(__file__), "assets", "OpenSans-Regular.ttf")
pdfmetrics.registerFont(TTFont('OpenSans', font_path))
for page_idx, pair in enumerate(text_pairs):
if page_idx >= total_pages:
break # Safety first
@@ -228,28 +234,27 @@ def overlay_text_on_pdf(base_pdf_path: str, output_pdf_path: str, texts: list):
can = canvas.Canvas(packet, pagesize=A4)
# Draw the text.
# We handle the "☑" character manually since Helvetica might not support it.
def draw_text_with_checkbox(can, x, y, text):
current_x = x
if text.startswith(" "):
# Draw a checkbox manually
can.setFont("OpenSans", 12)
if text.endswith(" "):
clean_text = text[:-2] # remove the checkmark part
can.drawString(x, y, clean_text)
# Calculate width to place the checkbox right after the text
text_width = can.stringWidth(clean_text, "OpenSans", 12)
box_x = x + text_width + 8
size = 10
# Draw box (baseline adjustment to align with text)
can.rect(x, y - 1, size, size)
# Draw checkmark
can.rect(box_x, y - 1, size, size)
can.setLineWidth(1.5)
can.line(x + 2, y + 3, x + 4.5, y + 0.5)
can.line(x + 4.5, y + 0.5, x + 8.5, y + 7)
can.line(box_x + 2, y + 3, box_x + 4.5, y + 0.5)
can.line(box_x + 4.5, y + 0.5, box_x + 8.5, y + 7)
can.setLineWidth(1)
# Move text X position to the right
current_x += size + 5
text = text[2:] # Remove the "☑ " from string
can.setFont("Helvetica", 12)
can.drawString(current_x, y, text)
else:
can.drawString(x, y, text)
if len(pair) > 0:
draw_text_with_checkbox(can, x_pos, y_pos_1, pair[0])
if len(pair) > 1:
draw_text_with_checkbox(can, x_pos, y_pos_2, pair[1])