我正在使用ReportLab和Python动态生成PDF文档。
我希望一行文本能够居中显示在页面上。以下是我目前的具体代码,但我不知道如何使文本水平居中。
header = p.beginText(190, 740)
header.textOut("Title of Page Here")
# I know i can use TextLine etc in place of textOut
p.drawText(header)
文本显示出来了,我可以手动移动左侧的位置使文本看起来居中,但由于文本是动态的且我不知道将有多少文本,因此需要通过编程来实现居中显示。
from reportlab.rl_settings import defaultPageSize
。 - joeyagreco