Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Aligning and centering a single Paragraph in ReportLab into a 1-page document

I want to have a 1-page PDF with a single paragraph but having it centralized both horizontally and vertically with reportlab. The TA_CENTER alignment when applied to the Paragraph below only seems to aligning the text horizontally, but it is not centering it to the center of the document.

style = getSampleStyleSheet()
normal = style["Normal"]
normal.alignment = TA_CENTER
normal.fontName = "Helvetica"
normal.fontSize = 15
normal.leading = 15

text = "Please be wrapped, centered horizontally and vertically!!"
pdf = SimpleDocTemplate(documentPath, pagesize = (250, 80), rightMargin=10, leftMargin=10, topMargin=5,bottomMargin=5)
story = []
para = Paragraph(text, normal)
story.append(para)
pdf.build(story)
like image 367
user1755180 Avatar asked Nov 04 '22 13:11

user1755180


1 Answers

Seems like the style alignment does not offer such a privilege to just set your text in the middle using platypus template.

I would say it's not possible using SimpleDocTemplate.

But if you wrapped it in a table. Then you can set the MIDDLE style to your table. Then it will work.

like image 186
Nicholas TJ Avatar answered Nov 11 '22 08:11

Nicholas TJ