python pdfkit中文乱码

在使用pdfkit 将html转化为pdf文件是出现了中文乱码的问题,在网上找了一下原因有两个
第一个 服务器不支持中文
第二个 在html文档当中需要标明编码格式

第二种不难说一下第一个,我使用的系统是centos7.2,
葵花宝典
第一式:检查系统是否有字体库

查看字体库列表

fc-list

如果没有安装字体库,使用下面的命令安装字体库

yum -y install fontconfig

第二式:安装中文字体

首先在/usr/shared/fonts 目录下新建一个目录 chinese。

mkdir /usr/shared/fonts/chinese

上传字体文件到 chinese 文件夹中。

simsun.ttc
simsunb.ttf

修改 chinese 目录的权限

chmod -R 755 /usr/share/fonts/chinese

安装 ttmkfdir 来搜索目录中所有的字体信息,并汇总生成 fonts.scale 文件。

yum -y install ttmkfdir

ttmkfdir -e /usr/share/X11/fonts/encodings/encodings.dir

修改字体配置文件,添加 chinese 文件夹的地址

vi /etc/fonts/fonts.conf

<dir>/usr/share/fonts</dir>
<dir>/usr/share/X11/fonts/Type1</dir> <dir>/usr/share/X11/fonts/TTF</dir> <dir>/usr/local/share/fonts</dir>

<!-- 添加chinese文件夹的地址 -->
<dir>/usr/share/fonts/chinese</dir>

<dir prefix="xdg">fonts</dir>
<!-- the following element will be removed in the future -->
<dir>~/.fonts</dir>

清除字体缓存

fc-cache

OKOK,接下来就是见证奇迹的时刻了。
感谢无名前辈留下的经验

Linux CentOS 7 安装字体库 & 中文字体:https://www.linuxidc.com/Linux/2016-09/135548.htm
centos系统怎么设置系统语言为中文:https://www.php.cn/centos/445626.html
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值