-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpdf_creator.py
51 lines (43 loc) · 1.75 KB
/
pdf_creator.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
from reportlab.lib import colors
from reportlab.lib.enums import TA_CENTER
from reportlab.lib.units import cm, inch
from reportlab.pdfbase import pdfmetrics
from reportlab.pdfbase.ttfonts import TTFont
from reportlab.platypus import SimpleDocTemplate, Table, TableStyle, Spacer, Paragraph
from reportlab.lib.pagesizes import A4, landscape
from reportlab.pdfgen import canvas
from reportlab.lib.styles import getSampleStyleSheet, ParagraphStyle
from io import BytesIO
stylesheet = getSampleStyleSheet()
pdfmetrics.registerFont(TTFont('TNR', 'static/signikan.ttf'))
def create_pdf(data, fileName, type, start_date, end_date, person, position):\
pdf=SimpleDocTemplate(
fileName,
pagesize=landscape(A4),
rightMargin=100,
leftMargin=100,
topMargin=50,
bottomMargin=50
)
table=Table(data)
elems=[]
style = ParagraphStyle(
name='Title',
fontName='TNR',
fontSize=12,
alignment=TA_CENTER)
style1 = ParagraphStyle(
name='footer',
fontName='TNR',
fontSize=10,
alignment=TA_CENTER)
elems.append(Paragraph(f"Wnioski {type} w okresie od {start_date} do {end_date}", style=style))
elems.append(Spacer(1, 16))
elems.append(Paragraph(f"{person} (stanowisko: {position})" , style=style))
elems.append(Spacer(1, 20))
elems.append(table)
style_table=TableStyle([('FONTNAME', (0, 0), (-1, -1), 'TNR'), ('FONTSIZE', (0, 0), (-1, -1), 12),('GRID',(0,0),(-1,-1),1,colors.black)])
table.setStyle(style_table)
elems.append(Spacer(1, 20))
elems.append(Paragraph("Wygenerowano automatycznie z Wnioski urlopowe 1.0", style=style1))
pdf.build(elems)