Update app.py
Browse files
app.py
CHANGED
|
@@ -63,8 +63,44 @@ def fetch_data():
|
|
| 63 |
|
| 64 |
# Function to handle Markdown conversion to PDF (Simplified and robust)
|
| 65 |
def md_to_pdf(md_text, pdf):
|
| 66 |
-
|
| 67 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 68 |
|
| 69 |
# Modified generate_pdf function to handle markdown
|
| 70 |
def generate_pdf(report_text):
|
|
|
|
| 63 |
|
| 64 |
# Function to handle Markdown conversion to PDF (Simplified and robust)
|
| 65 |
def md_to_pdf(md_text, pdf):
|
| 66 |
+
"""Renders basic Markdown to PDF using fpdf text functions (limited formatting)."""
|
| 67 |
+
md = markdown2.markdown(md_text) # Parse Markdown
|
| 68 |
+
|
| 69 |
+
lines = md.split('\n') # Split into lines
|
| 70 |
+
|
| 71 |
+
pdf.set_font("Arial", "", 12) # Set default font
|
| 72 |
+
|
| 73 |
+
for line in lines:
|
| 74 |
+
line = line.strip()
|
| 75 |
+
|
| 76 |
+
# Basic heading support (adjust as needed)
|
| 77 |
+
if line.startswith("# "):
|
| 78 |
+
pdf.set_font("Arial", "B", 18)
|
| 79 |
+
pdf.cell(0, 10, line[2:], ln=True)
|
| 80 |
+
elif line.startswith("## "):
|
| 81 |
+
pdf.set_font("Arial", "B", 16)
|
| 82 |
+
pdf.cell(0, 10, line[3:], ln=True)
|
| 83 |
+
elif line.startswith("### "):
|
| 84 |
+
pdf.set_font("Arial", "B", 14)
|
| 85 |
+
pdf.cell(0, 10, line[4:], ln=True)
|
| 86 |
+
|
| 87 |
+
# Basic bold text support (very limited)
|
| 88 |
+
elif "**" in line:
|
| 89 |
+
parts = line.split("**")
|
| 90 |
+
for i, part in enumerate(parts):
|
| 91 |
+
if i % 2 == 1: # Bold text
|
| 92 |
+
pdf.set_font("Arial", "B", 12)
|
| 93 |
+
pdf.cell(0, 10, part, ln=False) # Don't add newline for inline bold
|
| 94 |
+
else:
|
| 95 |
+
pdf.set_font("Arial", "", 12)
|
| 96 |
+
pdf.cell(0, 10, part, ln=False)
|
| 97 |
+
pdf.ln() # Newline after the whole line
|
| 98 |
+
|
| 99 |
+
# Add other basic formatting as needed...
|
| 100 |
+
|
| 101 |
+
else: # Normal text
|
| 102 |
+
pdf.set_font("Arial", "", 12)
|
| 103 |
+
pdf.multi_cell(0, 10, line)
|
| 104 |
|
| 105 |
# Modified generate_pdf function to handle markdown
|
| 106 |
def generate_pdf(report_text):
|