[Python] why can't I add DejaVu font to fpdf in PyCharm?

Discussão em 'Python' iniciado por Stack, Abril 8, 2025.

  1. Stack

    Stack Membro Participativo

    I'm new to fpdf and python, so I'm sure this is probably something very simple, but I can't seem to add a utf-8 compatible font, in this case DejaVu. I have placed the font folder downloaded together with FPDF in just about every other folder on my mac running OS 10.15.7. I'm using PyCharm 2020.3 with python 3.9.

    I get the following output:

    /usr/local/bin/python3.9 /Users/brc/Documents/Python/AvenidasPython/FontTest.py

    Traceback (most recent call last):
    File "/Users/brc/Documents/Python/AvenidasPython/FontTest.py", line 5, in <module>
    pdf.add_font('DejaVu', '', 'DejaVuSansCondensed.ttf', uni=True)
    File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/fpdf/fpdf.py", line 577, in add_font
    if (Path(parent) / fname).exists():
    File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/pathlib.py", line 1071, in __new__
    self = cls._from_parts(args, init=False)
    File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/pathlib.py", line 696, in _from_parts
    drv, root, parts = self._parse_args(args)
    File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/pathlib.py", line 680, in _parse_args
    a = os.fspath(a)
    TypeError: expected str, bytes or os.PathLike object, not NoneType

    Process finished with exit code 1


    Originally the issue appeared in a more complex script, but I get the same error from the simplest of scripts:

    from fpdf import FPDF

    pdf = FPDF('L', 'mm', 'A4')
    pdf.add_page()
    pdf.add_font('DejaVu', '', 'DejaVuSansCondensed.ttf', uni=True)


    It seems to me that this is something linear so I didn't bother contextualizing why I need this to work, but I can do so if required. Thanks in advance!

    Continue reading...

Compartilhe esta Página