Python 生成PDF生僻字无效显示的问题

在使用Python生成PDF时遇到生僻字如'刘偲'无法正常显示的问题,通过替换字体为微软雅黑成功解决。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在做个一个python 自动生成A4纸标签的程序,所以事情都做完了,最后发现竟然有些人都名字显示不全。
例如,有个同学叫“刘偲”,但是生成都PDF却无法显示

# encoding: utf-8
from reportlab.lib import colors
from reportlab.graphics.shapes import *
import labels
from reportlab.graphics import shapes
import os.path
import labels
import os.path
from reportlab.pdfbase.ttfonts import TTFont
from reportlab.pdfbase.pdfmetrics import registerFont, stringWidth
from reportlab.graphics import shapes
from reportlab.lib import colors

base_path = os.path.dirname(__file__)
registerFont(TTFont('song', os.path.join(base_path, 'song.ttf')))
registerFont(TTFont('heiti', os.path.join(base_path, 'fangsong.ttf')))


d = Drawing(400, 200)
d.add(Rect(50, 50, 300, 100, fillColor=colors.yellow))
d.add(String(150,100, 'Hello World', f
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

知识大胖

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值