Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -113,12 +113,23 @@ def build_table(title, rows):
|
|
| 113 |
return html
|
| 114 |
|
| 115 |
|
| 116 |
-
# Generate PDF report using FPDF
|
| 117 |
def generate_pdf(report_html):
|
| 118 |
pdf = FPDF()
|
| 119 |
pdf.set_auto_page_break(auto=True, margin=15)
|
|
|
|
|
|
|
| 120 |
pdf.add_page()
|
| 121 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 122 |
|
| 123 |
# Add a title
|
| 124 |
pdf.cell(200, 10, txt="Face-Based Health Report", ln=True, align="C")
|
|
|
|
| 113 |
return html
|
| 114 |
|
| 115 |
|
| 116 |
+
# Generate PDF report using FPDF with support for UTF-8 characters (like emojis)
|
| 117 |
def generate_pdf(report_html):
|
| 118 |
pdf = FPDF()
|
| 119 |
pdf.set_auto_page_break(auto=True, margin=15)
|
| 120 |
+
|
| 121 |
+
# Add a page to the PDF
|
| 122 |
pdf.add_page()
|
| 123 |
+
|
| 124 |
+
# Add a custom font (download a TTF font that supports Unicode characters and emojis)
|
| 125 |
+
# Here, 'Arial Unicode MS' is used as an example, but you can use any font supporting emojis
|
| 126 |
+
# Make sure to have the TTF file in your project and pass it as an argument to add_font
|
| 127 |
+
try:
|
| 128 |
+
pdf.add_font('ArialUnicode', '', '/path/to/ArialUnicodeMS.ttf', uni=True)
|
| 129 |
+
pdf.set_font('ArialUnicode', '', 12)
|
| 130 |
+
except Exception as e:
|
| 131 |
+
print(f"Error loading font: {e}")
|
| 132 |
+
pdf.set_font('Arial', '', 12) # Fallback to a default font if custom font fails
|
| 133 |
|
| 134 |
# Add a title
|
| 135 |
pdf.cell(200, 10, txt="Face-Based Health Report", ln=True, align="C")
|