You have two options:
Use built-in fonts: Replace the font name "dejavusanscondensedB" with one of the built-in fonts in pyfpdf. You can choose from the following fonts: Courier, Helvetica, Times, Symbol, ZapfDingbats.
Add the font using FPDF.addfont() function beforehand: If you want to use the specific font "dejavusanscondensedB", you need to add it to pyfpdf using the FPDF.addfont() function.
Here is an example of how to add a font using the FPDF.add_font() function:
from fpdf import FPDF
class MyPDF(FPDF):
def __init__(self):
super().__init__()
self.add_font('DejaVuSansCondensed', '', 'DejaVuSansCondensed.ttf', uni=True)
def create_pdf(self):
self.add_page()
self.set_font('DejaVuSansCondensed', '', 12)
self.cell(0, 10, 'Hello World')
self.output('output.pdf')
MyPDF().create_pdf()
Make sure to replace the font name, file name, and font size with your own values.
Asked: 2023-06-19 01:23:33 +0000
Seen: 11 times
Last updated: Jun 19 '23