How to set any font in reportlab Canvas in python?
问题 I'm using reportlab to create pdfs. When I try to set a font using the following method, I get a KeyError : pdf = Canvas('test.pdf') pdf.setFont('Tahoma', 16) But if I use 'Courier' instead of 'Tahoma' there isn't a problem. How can I use Tahoma? 回答1: Perhabs Tahoma is a TrueType font, and you need to register it first. According to the user guide of ReportLab you need to do this: from reportlab.pdfbase import pdfmetrics from reportlab.pdfbase.ttfonts import TTFont pdfmetrics.registerFont