-1
I’m doing the exporting of reports through the library reportlab. To insert the text I used the canvas module, and wrote this code that works well.
from reportlab.pdfgen import canvas
pdf = canvas.Canvas('exemple3.pdf', pagesize=A4)
pdf.setFillColor(aColor='blue')
pdf.setFont('Helvetica', 14)
pdf.drawString(55, 740, 'RELATÓRIO FEVEREIRO 2021')
pdf.setFillColor(aColor='black')
pdf.setFont('Helvetica', 22)
pdf.drawString(55, 715, 'PROJECTOS')
pdf.drawString(55, 695, 'MINOR HOTEL GROUP')
pdf.drawString(55, 675, 'HOTÉIS TIVOLI PORTUGAL')
pdf.save()
Next I will need to insert a table in the PDF and for that I discovered that the Simpledoctemplate module could help me and so I created the following code that works well separate from the previous one:
from reportlab.lib import colors
from reportlab.lib.pagesizes import A4
from reportlab.platypus import SimpleDocTemplate, Table, TableStyle
elements = []
data= [['Periodo a que diz respeito', startdate + ' a ' + enddate],
[' ', ' '],
['Horas despendidas no período de 01/01/2021 a 20/01/2021', '271,04'],
['Por rubrica:', ' ']]
t=Table(data)
t.setStyle(TableStyle([('BOX', (0,0), (-1,-1), 0.25, colors.black),
('INNERGRID', (0,0), (-1,-1), 0.25, colors.black),
('ALIGN',(1,1),(-3,-3),'RIGHT'),
('VALIGN',(0,-1),(-1,-1),'MIDDLE'),
('TEXTCOLOR',(0,0),(1,-1),colors.black)]))
elements.append(t)
pfd.build(elements)
My question is, how do I put these two codes together? If you have another solution, I’d appreciate it :)