Align and center a single paragraph in ReportLab in a one-page document

I want to have a 1-page PDF file with one paragraph, but it is centralized both horizontally and vertically with reportlab. Aligning TA_CENTER when applied to the paragraph below seems to align the text horizontally, but does not center it in 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) 
+4
source share
1 answer

It seems that style alignment does not give such privilege to just set your text in the middle using the platypus template.

I would say that this is not possible with SimpleDocTemplate.

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

+2
source

Source: https://habr.com/ru/post/1441975/


All Articles