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.
Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss
Asked: 2023-06-19 01:23:33 +0000
Seen: 11 times
Last updated: Jun 19 '23
How can popen() be used to direct streaming data to TAR?
In Python, can a string be utilized to retrieve a dataframe that has the same name as the string?
What is the method for merging field value and text into a singular line for display?
What is the method for programmatic access to a time series?