Skip to content
Advertisement

Problem importing fonts with FPDF using python

I’ve been trying to import specialty fonts beyond what is default included with the FPDF package with Python, using the pdf.add_font() command. The code below produces an error of an Undefined font, as though I didn’t just use pdf.add_font(). Below you can find a sample of my code, as well as proof that the relevant fonts are in the directory specified in the pdf.add_font() command. I have also tried installing the relevant fonts in the C:WindowsFonts directory.

JavaScript

Relevant error message:

JavaScript

Proof of fonts in the correct directory

Thank you!

Advertisement

Answer

This line:

JavaScript

creates a brand-new FPDF instance and helpfully deletes the one in which you so carefully added the fonts. You need to add the fonts to the instance you’re actually using.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement