Skip to content

Commit

Permalink
Fix #153
Browse files Browse the repository at this point in the history
  • Loading branch information
cmutel committed Apr 9, 2024
1 parent 5751de3 commit 5c0f0d5
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 7 deletions.
22 changes: 16 additions & 6 deletions dds_registration/core/helpers/create_pdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@
font_size = 12


def normalize_text(text: str) -> str:
return text.encode('utf-8', 'ignore').decode('utf-8').strip()


def create_pdf(
kind: str,
client_name: str,
Expand All @@ -53,14 +57,20 @@ def create_pdf(

# Create pdf...
pdf = FPDF(unit="mm", format="A4")

pdf.add_font("NotoSans", style="", fname=BASE_DIR / "fonts" / "NotoSans-Regular.ttf", uni=True)
pdf.add_font("NotoSans", style="B", fname=BASE_DIR / "fonts" / "NotoSans-Bold.ttf", uni=True)
pdf.add_font("NotoSans", style="I", fname=BASE_DIR / "fonts" / "NotoSans-Italic.ttf", uni=True)
pdf.add_font("NotoSans", style="BI", fname=BASE_DIR / "fonts" / "NotoSans-BoldItalic.ttf", uni=True)

pdf.set_title("{} {} ({})".format(kind.title(), invoice_number, client_name))
pdf.set_margins(left=margin_size, top=margin_size, right=margin_size)

# Get full page width (mm)...
page_width = pdf.epw

pdf.add_page()
pdf.set_font("times", size=font_size)
pdf.set_font("NotoSans", size=font_size)

# Get derived dimensions...
pdf_font_size = pdf.font_size
Expand All @@ -77,11 +87,11 @@ def create_pdf(

# Left (client) address column...
pdf.set_xy(left_column_pos, margin_size + top_offset)
pdf.multi_cell(text=client_name, w=left_column_width, align=Align.L, new_x="LEFT", new_y="NEXT", h=line_height)
pdf.multi_cell(text=normalize_text(client_name), w=left_column_width, align=Align.L, new_x="LEFT", new_y="NEXT", h=line_height)

pdf.set_y(pdf.get_y() + small_vertical_space)
pdf.multi_cell(
text=client_address.strip(), w=left_column_width, align=Align.L, new_x="LEFT", new_y="NEXT", h=line_height
text=normalize_text(client_address), w=left_column_width, align=Align.L, new_x="LEFT", new_y="NEXT", h=line_height
)

left_stop_pos = pdf.get_y()
Expand Down Expand Up @@ -181,7 +191,7 @@ def create_pdf(
)
pdf.set_y(pdf.get_y() + tiny_vertical_space)
pdf.multi_cell(
text=recipient_account.strip(),
text=recipient_account,
markdown=True,
w=page_width,
align=Align.L,
Expand All @@ -193,8 +203,8 @@ def create_pdf(
if extra:
pdf.set_y(pdf.get_y() + large_vertical_space)
pdf.multi_cell(
text="__{}__".format(extra),
markdown=True,
text=normalize_text(extra),
markdown=False,
w=page_width,
align=Align.L,
new_x="LEFT",
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
2 changes: 1 addition & 1 deletion dds_registration/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class MembershipForm(forms.Form):
)
address = forms.CharField(label="Address on invoice", widget=textAreaWidget, required=True)
extra = forms.CharField(
label="Extra invoice text details, like reference or purchase order numbers",
label="Extra invoice text details, like reference or purchase order numbers. Support Latin, Cyrillic and Greek scripts, but not emojis.",
widget=textAreaWidget,
required=False,
)
Expand Down

0 comments on commit 5c0f0d5

Please sign in to comment.