gpt4 book ai didi

python - Reportlab 和 Fontawesome 字体

转载 作者:行者123 更新时间:2023-12-01 05:17:29 26 4
gpt4 key购买 nike

如何使用FontawesomeReportlab ?我遇到一些错误,但没有找到任何解决方案

from reportlab.pdfbase import pdfmetrics
from reportlab.pdfbase.ttfonts import TTFont
from reportlab.pdfgen import canvas

pdffile = 'test.pdf'
ttffile = '/somepath/fonts/fontawesome-webfont.ttf'

c = canvas.Canvas(pdffile)
pdfmetrics.registerFont(TTFont('fontawesome', ttffile))
c.setFont('fontawesome', 32)
c.drawString(10, 150, "test")
c.showPage()
c.save()

.

Traceback (most recent call last):
File "/somepath/test.py", line 9, in <module>
pdfmetrics.registerFont(TTFont('fontawesome', ttffile))
File "/usr/local/lib/python3.3/dist-packages/reportlab/pdfbase/ttfonts.py", line 989, in __init__
self.face = TTFontFace(filename, validate=validate, subfontIndex=subfontIndex)
File "/usr/local/lib/python3.3/dist-packages/reportlab/pdfbase/ttfonts.py", line 895, in __init__
TTFontFile.__init__(self, filename, validate=validate, subfontIndex=subfontIndex)
File "/usr/local/lib/python3.3/dist-packages/reportlab/pdfbase/ttfonts.py", line 394, in __init__
self.extractInfo(charInfo)
File "/usr/local/lib/python3.3/dist-packages/reportlab/pdfbase/ttfonts.py", line 469, in extractInfo
psName = names[6].replace(b" ", b"-") #Dinu Gherman's fix for font names with spaces
TypeError: Can't convert 'bytes' object to str implicitly

报告实验室 = 3.0

Python = 3.3.2

最佳答案

请勿使用网站上的fontawesome-webfont.ttf。使用 everythingfonts.comFontAwesome.otf 转换为 .ttf

关于python - Reportlab 和 Fontawesome 字体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22960538/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com