将 ReportLab 中的单个段落对齐并居中到一页文档中

use*_*180 5 python reportlab

我想要一个包含单个段落的 1 页 PDF,但使用 reportlab 将其水平和垂直集中。当应用于下面的段落时,TA_CENTER 对齐似乎只是水平对齐文本,但它并没有将其居中到文档的中心。

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)
Run Code Online (Sandbox Code Playgroud)

Nic*_* TJ 3

似乎样式对齐不提供这样的特权,只需使用鸭嘴兽模板将文本设置在中间。

我想说使用 SimpleDocTemplate 是不可能的。

但如果你把它包裹在桌子里。然后您可以将 MIDDLE 样式设置为您的表格。然后它就会起作用。