Spaces:
Sleeping
Sleeping
Update pdf_utils.py
Browse files- pdf_utils.py +17 -25
pdf_utils.py
CHANGED
|
@@ -1,28 +1,20 @@
|
|
| 1 |
-
from reportlab.lib.pagesizes import A4
|
| 2 |
-
from reportlab.
|
| 3 |
-
|
| 4 |
|
| 5 |
-
def export_pdf(df
|
| 6 |
-
|
| 7 |
-
|
| 8 |
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
c.drawString(x, y, line)
|
| 21 |
-
y -= 18
|
| 22 |
-
|
| 23 |
-
if y < 40:
|
| 24 |
-
c.showPage()
|
| 25 |
-
y = height - 40
|
| 26 |
-
|
| 27 |
-
c.save()
|
| 28 |
return filename
|
|
|
|
| 1 |
+
from reportlab.lib.pagesizes import A4, landscape
|
| 2 |
+
from reportlab.platypus import SimpleDocTemplate, Table, TableStyle
|
| 3 |
+
from reportlab.lib import colors
|
| 4 |
|
| 5 |
+
def export_pdf(df, filename="timetable.pdf"):
|
| 6 |
+
pdf = SimpleDocTemplate(filename, pagesize=landscape(A4))
|
| 7 |
+
data = [df.columns.tolist()] + df.values.tolist()
|
| 8 |
|
| 9 |
+
table = Table(data)
|
| 10 |
+
style = TableStyle([
|
| 11 |
+
('BACKGROUND', (0,0), (-1,0), colors.lightblue),
|
| 12 |
+
('TEXTCOLOR', (0,0), (-1,0), colors.white),
|
| 13 |
+
('ALIGN', (0,0), (-1,-1), 'CENTER'),
|
| 14 |
+
('VALIGN', (0,0), (-1,-1), 'MIDDLE'),
|
| 15 |
+
('GRID', (0,0), (-1,-1), 1, colors.black),
|
| 16 |
+
('FONTSIZE', (0,0), (-1,-1), 10)
|
| 17 |
+
])
|
| 18 |
+
table.setStyle(style)
|
| 19 |
+
pdf.build([table])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
return filename
|