【问题标题】:Can I get the formatted text size using ReportLab in Python?我可以在 Python 中使用 ReportLab 获取格式化的文本大小吗?
【发布时间】:2019-08-01 12:09:52
【问题描述】:

是否可以在 reportLab 中获取渲染文本的大小/范围?

我需要计算一些相对于页面上其他元素的位置。

流动系统不是我想要的。如有必要,我不介意使用它来获取尺寸,但这不适合我的整体布局。 我尝试创建 Paragraph 和调用 wrap,但它始终返回可用宽度,而不是测量的扩展。

【问题讨论】:

    标签: python python-3.x pdf reportlab text-formatting


    【解决方案1】:

    您可以使用stringWidth 获得渲染文本的宽度:

    from reportlab.pdfbase.pdfmetrics import stringWidth
    width = stringWidth(text, font_name, font_size)
    

    行距为您提供了一行文本的高度。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-04-11
      • 1970-01-01
      • 1970-01-01
      • 2017-03-09
      • 2013-08-16
      • 2012-10-23
      • 1970-01-01
      相关资源
      最近更新 更多