user1755180
user1755180

Reputation: 191

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)

Upvotes: 5

Views: 10011

Answers (1)

Nicholas TJ
Nicholas TJ

Reputation: 1659

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.

Upvotes: 3

Related Questions