-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreports.py
21 lines (18 loc) · 939 Bytes
/
reports.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#!/usr/bin/env python3
import reportlab
from reportlab.platypus import SimpleDocTemplate
from reportlab.platypus import Paragraph, Spacer, Table, Image
from reportlab.lib.styles import getSampleStyleSheet
from reportlab.lib import colors
def generate(filename, title, additional_info, table_data):
"""Generates a PDF file with data given in the parameters."""
styles = getSampleStyleSheet()
report = SimpleDocTemplate(filename)
report_title = Paragraph(title, styles["h1"])
report_info = Paragraph(additional_info, styles["BodyText"])
table_style = [('GRID', (0, 0), (-1, -1), 1, colors.black),
('FONTNAME', (0, 0), (-1, 0), 'Helvetica-Bold'),
('ALIGN', (0, 0), (-1, -1), 'CENTER')]
report_table = Table(data=table_data, style=table_style, hAlign="LEFT")
empty_line = Spacer(1, 20)
report.build([report_title, empty_line, report_info, empty_line, report_table])