G
We're not joining the Canvas method with SimpleDocTemplate, it doesn't make sense.
After several researches what I've come up with is that Canvas is great for generating text, simpler documents and for initially to realize a bit of the library reportlabThe solution I got was the following:I imported two more variants of the reportlab and kept the same code to generate the table.from reportlab.platypus import Paragraph
from reportlab.lib.styles import ParagraphStyle
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)]))
The text is being added to the array elements through the variable Paragraph of the reportlab. The style variable is the one that will give another aspect to this text.style = ParagraphStyle('heading1',
fontName = 'Helvetica-Bold',
fontSize = 20,
textColor = colors.black,
leading = 20)
elements.append(Paragraph('RELATÓRIO FEVEREIRO 2021', style))
elements.append(Paragraph('PROJECTOS', style))
elements.append(Paragraph('TIVOLI HOTEIS', style))
elements.append(t)#adiciona a tabela à variavel elements
pdf = SimpleDocTemplate('exemple3.pdf', pagesize=A4)
pfd.build(elements)
Finally, 'pdf.build(elements)' will add the text and table to the PDF report, with the formatting configured.I'm new around here, I'm sorry if I didn't explain well. Feel free to ask questions.