Python ReportLab:中心字符串
Python ReportLab: Center string
我目前正在放置一个字符串:
can = canvas.Canvas(packet, pagesize=letter)
can.setFont('Helvetica-Bold',12) # Change Font, Font-size, etc
can.drawString(300, 340, row["name"]) # Change position. First number = points from left, secoond = points from bottom
我现在需要将绳子居中,即只要给拉绳高度,绳子本身就必须始终居中。
我在网上搜索过,但找不到简单的方法。我在监督什么吗?
感谢
始终尝试以这种方式将文本放入段落中,您始终可以按照自己的方式自定义文本。
doc = SimpleDocTemplate("paragraph_spacing.pdf",
pagesize=letter
)
# creating custom stylesheet
styles = getSampleStyleSheet()
styles.add(ParagraphStyle(name='my_custom_name', fontName="Helvetica-Bold", fontSize=12, leftIndent=200))
# giving alias to the stylesheet
my_style = styles['my_custom_name']
flowables = []
flowables.append(Spacer(0, 0))
# using the stylesheet
flowables.append(Paragraph(row["name"], my_style))
doc.build(flowables)
您可以使用 Spacer(0, height)
指定高度并使用 leftIndent
标记文档宽度的中心
我目前正在放置一个字符串:
can = canvas.Canvas(packet, pagesize=letter)
can.setFont('Helvetica-Bold',12) # Change Font, Font-size, etc
can.drawString(300, 340, row["name"]) # Change position. First number = points from left, secoond = points from bottom
我现在需要将绳子居中,即只要给拉绳高度,绳子本身就必须始终居中。
我在网上搜索过,但找不到简单的方法。我在监督什么吗?
感谢
始终尝试以这种方式将文本放入段落中,您始终可以按照自己的方式自定义文本。
doc = SimpleDocTemplate("paragraph_spacing.pdf",
pagesize=letter
)
# creating custom stylesheet
styles = getSampleStyleSheet()
styles.add(ParagraphStyle(name='my_custom_name', fontName="Helvetica-Bold", fontSize=12, leftIndent=200))
# giving alias to the stylesheet
my_style = styles['my_custom_name']
flowables = []
flowables.append(Spacer(0, 0))
# using the stylesheet
flowables.append(Paragraph(row["name"], my_style))
doc.build(flowables)
您可以使用 Spacer(0, height)
指定高度并使用 leftIndent
标记文档宽度的中心