Opera of the Phantom
Opera of the Phantom

Reputation: 45

Define fonts for re-use in python fpdf

I´m building PDF document in python with fpdf. Fonts are set in the following way:

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

However, this seems a bit unclear if I have to change the font several times (for headings, sub headings, regular text and so on). So I was trying to define fonts upfront in the following form:

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

And then use the defined fonts later:

pdf.set_font(heading)

Unfortunately this results in the following error:

 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'

So I was wondering, is there any other way to achieve this?

Upvotes: 1

Views: 1090

Answers (1)

Lakerr
Lakerr

Reputation: 97

Try to use this:

pdf.set_font(*heading)

Upvotes: 2

Related Questions