【问题标题】:Python ReportLab: Center stringPython ReportLab:中心字符串
【发布时间】:2018-07-23 16:04:13
【问题描述】:

我目前正在放置一个字符串:

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

我现在需要将绳子居中,即只给拉绳高度,绳子本身必须始终居中。

我在网上搜索过,但找不到一个简单的方法。我在监督什么吗?

谢谢

【问题讨论】:

    标签: python-3.x reportlab


    【解决方案1】:

    始终尝试将您的文本放在一个段落中,这样您就可以随时以您想要的方式自定义您的文本。

    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 标记文档宽度的中心

    【讨论】:

      猜你喜欢
      • 2014-06-18
      • 1970-01-01
      • 2020-12-25
      • 2012-11-03
      • 2016-05-31
      • 1970-01-01
      • 2017-04-09
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多