0
pdf.add_font('DejaVu', '', 'DejaVuSansCondensed.ttf', uni=True)

Works only in PyCharm console, if run from the command line i get an error


File "C:\\Program Files\\Python310\\lib\\site-packages\\fpdf\\fpdf.py", line 469, in add_font
raise RuntimeError("TTF Font file not found: %s" % fname)
RuntimeError: TTF Font file not found: DejaVuSansCondensed.ttf
←\[?25h

the font is at the root

when using pycharm, an additional file is automatically created DejaVuSansCondensed.pkl and everything works fine, but when using the command line, the file is not created and I get an error. Please help me with the solution.

  • "the font is at the root" - well, the "root", or "Current Working Directory" (short CWD) isn't always where your main python file is. Your CWD can change for various reasons, running from command line being one of them. Thus it's almost always better to build absolute pathes instead of relying on relative pathes. Related: [You can use ``__file__`` to build your absolute path.](https://stackoverflow.com/questions/9271464/what-does-the-file-variable-mean-do) – Mike Scotty Jan 16 '23 at 14:08

1 Answers1

1

FPDF only works with absolute path, works in this form:

path = os.path.abspath('DejaVuSansCondensed.ttf')
pdf.add_font('DejaVu', '', path, uni=True)