renderPM找不到'Times-Roman'的.pfb

问题描述 投票:0回答:1

完整错误日志:

Warn: Can't find .pfb for face 'Times-Roman'
Traceback (most recent call last):
  File "lib\site-packages\reportlab\graphics\renderPM.py", line 242, in _setFont
ValueError: _renderPM.gstate_setFont: Can't find font!

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "lib\site-packages\reportlab\graphics\renderPM.py", line 248, in _setFont
TypeError: makeT1Font() argument 2 must be str, not None

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "main.py", line 69, in run
  File "lib\site-packages\reportlab\graphics\renderPM.py", line 680, in drawToFile
  File "lib\site-packages\reportlab\graphics\renderPM.py", line 666, in drawToPMCanvas
  File "lib\site-packages\reportlab\graphics\renderPM.py", line 51, in draw
  File "lib\site-packages\reportlab\graphics\renderbase.py", line 204, in draw
  File "lib\site-packages\reportlab\graphics\renderPM.py", line 98, in initState
  File "lib\site-packages\reportlab\graphics\renderPM.py", line 92, in applyState
  File "lib\site-packages\reportlab\graphics\renderPM.py", line 399, in setFont
  File "lib\site-packages\reportlab\graphics\renderPM.py", line 251, in _setFont
reportlab.graphics.renderPM.RenderPMError: Can't setFont(Times-Roman) missing the T1 files?
Originally <class 'TypeError'>: makeT1Font() argument 2 must be str, not None

我已经尝试过here的答案,但是没有解决任何问题。

我已将文件提取到建议here的fonts文件夹中,但没有任何作用。

如果这可能是问题之一,我正在使用虚拟环境。

我尝试添加名称为Times-Roman的字体,但效果不佳。

[请注意,我使用的是Windows操作系统,使用Pyinstaller构建应用程序时会发生此错误。

这是我的目录的样子:

dxf2png/Lib/site-packages/reportlab/fonts

00readme.txt
bitstream-vera-license.txt
callig15.afm
callig15.pfb
cobo____.pfb
cob_____.pfb
com_____.pfb
coo_____.pfb
DarkGarden-changelog.txt
DarkGarden-copying-gpl.txt
DarkGarden-copying.txt
DarkGarden-readme.txt
DarkGarden.sfd
DarkGardenMK.afm
DarkGardenMK.pfb
sy______.pfb
Vera.ttf
VeraBd.ttf
VeraBI.ttf
VeraIt.ttf
zd______.pfb
zx______.pfb
zy______.pfb
_abi____.pfb
_ab_____.pfb
_ai_____.pfb
_a______.pfb
_ebi____.pfb
_eb_____.pfb
_ei_____.pfb
_er_____.pfb
python python-3.x reportlab
1个回答
0
投票

this user guide中,您会找到所需的所有内容(尤其是第48-52页)。

基本上,您需要以Adobe .afm('Adobe Font Metrics')和.pfb('Printer Font Binary')格式包括字体描述文件。

因此这是DarkGardenMK的示例,从那里获取:

import os
import reportlab
folder = os.path.dirname(reportlab.__file__) + os.sep + 'fonts'
afmFile = os.path.join(folder, 'DarkGardenMK.afm')
pfbFile = os.path.join(folder, 'DarkGardenMK.pfb')

from reportlab.pdfbase import pdfmetrics
justFace = pdfmetrics.EmbeddedType1Face(afmFile, pfbFile)
faceName = 'DarkGardenMK' # pulled from AFM file
pdfmetrics.registerTypeFace(justFace)
justFont = pdfmetrics.Font('DarkGardenMK', faceName, 'WinAnsiEncoding')
pdfmetrics.registerFont(justFont)
canvas.setFont('DarkGardenMK', 32)
canvas.drawString(10, 150, 'This should be in')
canvas.drawString(10, 100, 'DarkGardenMK')

因此,请测试它是否可以工作-您可以直接使用该字体,如果它确实对Times-Roman字体(以及相应的.afm,.pfb文件)也是如此。如果失败,请参阅第51页,“ TrueType字体支持”的说明。

希望有帮助!

© www.soinside.com 2019 - 2024. All rights reserved.