Spaces:
Sleeping
Sleeping
Create utils/helpers.py
Browse files- utils/helpers.py +27 -0
utils/helpers.py
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# utils/helpers.py
|
| 2 |
+
|
| 3 |
+
from fpdf import FPDF
|
| 4 |
+
import os
|
| 5 |
+
from datetime import datetime
|
| 6 |
+
|
| 7 |
+
def generate_pdf(title, content):
|
| 8 |
+
pdf = FPDF()
|
| 9 |
+
pdf.add_page()
|
| 10 |
+
pdf.set_font("Arial", size=12)
|
| 11 |
+
|
| 12 |
+
pdf.set_text_color(40, 40, 40)
|
| 13 |
+
pdf.cell(200, 10, txt=title.upper(), ln=True, align="C")
|
| 14 |
+
|
| 15 |
+
pdf.set_font("Arial", size=11)
|
| 16 |
+
pdf.multi_cell(0, 10, txt=content)
|
| 17 |
+
|
| 18 |
+
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
|
| 19 |
+
filename = f"{title.replace(' ', '_').lower()}_{timestamp}.pdf"
|
| 20 |
+
|
| 21 |
+
export_dir = "exports"
|
| 22 |
+
os.makedirs(export_dir, exist_ok=True)
|
| 23 |
+
|
| 24 |
+
path = os.path.join(export_dir, filename)
|
| 25 |
+
pdf.output(path)
|
| 26 |
+
|
| 27 |
+
return path
|