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

2024-03-29 08:09:39 发布

您现在位置:Python中文网/ 问答频道 /正文

我想有一个单一段落的1页PDF,但它集中在水平和垂直与reportlab。当应用于下面的段落时,TA_中心对齐看起来只是水平对齐文本,但它没有将文本居中到文档的中心。

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)

Tags: text文档文本pdfstyle水平中心段落
1条回答
网友
1楼 · 发布于 2024-03-29 08:09:39

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

我认为不可能使用SimpleDocTemplate。

但如果你把它包在桌子里。然后可以将中间样式设置为表。那就行了。

相关问题 更多 >