【问题标题】:Define fonts for re-use in python fpdf定义字体以在 python fpdf 中重用
【发布时间】:2021-07-07 11:41:20
【问题描述】:

我正在使用 fpdf 在 python 中构建 PDF 文档。字体设置如下:

pdf.set_font('arial', 'B', 20)  

但是,如果我必须多次更改字体(对于标题、子标题、常规文本等),这似乎有点不清楚。所以我试图以以下形式预先定义字体:

heading = ["arial", "B", 20]
sub_heading = ["arial", "B", 15]

然后再使用定义好的字体:

pdf.set_font(heading)

很遗憾,这会导致以下错误:

 Traceback (most recent call last):
  File "C:\Users\me\PycharmProjects\pythonProject\project\main.py", line 112, in <module>
    pdf.set_font(heading)
  File "C:\Users\me\PycharmProjects\pythonProject\project\venv\lib\site-packages\fpdf\fpdf.py", line 567, in set_font
    family=family.lower()
AttributeError: 'list' object has no attribute 'lower'

所以我想知道,还有其他方法可以实现吗?

【问题讨论】:

    标签: python-3.x fpdf


    【解决方案1】:

    尝试使用这个:

    pdf.set_font(*heading)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-01-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-05-17
      • 2013-07-03
      • 1970-01-01
      相关资源
      最近更新 更多