在centos7.5上安装wkhtmltopdf
rpm -ivh /home/zjb/wkhtmltox-0.12.6-1.centos7.x86_64.rpm
根据提示安装缺失依赖
yum install -y libX11 libXext libXrender libjpeg xorg-x11-fonts-75dpi xorg-x11-fonts-Type1
确认安装的中文字体
上传字体文件到/usr/share/fonts/chinese,
然后执行字体缓存更新
fc-cache -fv
检测linux上安装的中文字体
fc-list :lang=zh-cn
[root@webadmin01 chinese]# fc-list :lang=zh-cn
/usr/share/fonts/chinese/youyuan.TTF: YouYuan:style=Regular
/usr/share/fonts/chinese/Songti.ttc: STSong:style=Regular,Normaali
/usr/share/fonts/chinese/Songti.ttc: Songti TC,宋体\-繁,宋體\-繁:style=Regular,常规体,標準體
/usr/share/fonts/chinese/Songti.ttc: Songti SC,宋体\-简,宋體\-簡:style=Regular,常规体,標準體
/usr/share/fonts/chinese/MSYH.TTC: Microsoft YaHei:style=Normal
/usr/share/fonts/chinese/SIMSUN.TTC: SimSun,宋体:style=Regular,常规
/usr/share/fonts/chinese/Songti.ttc: Songti SC,宋体\-简,宋體\-簡:style=Light,细体,細體
/usr/share/fonts/chinese/MSYHBD.TTC: Microsoft YaHei:style=Έντονα
/usr/share/fonts/chinese/STKAITI.TTF: STKaiti:style=Regular
/usr/share/fonts/chinese/Songti.ttc: Songti TC,宋体\-繁,宋體\-繁:style=Light,细体,細體
/usr/share/fonts/chinese/MSYH.TTC: Microsoft YaHei UI:style=Normal
/usr/share/fonts/chinese/隶书.ttf: LiSu:style=Regular
/usr/share/fonts/chinese/MSYHBD.TTC: Microsoft YaHei UI:style=Έντονα
/usr/share/fonts/chinese/STFANGSO.TTF: STFangsong:style=Regular
/usr/share/fonts/chinese/SIMSUN.TTC: NSimSun,新宋体:style=Regular,常规
/usr/share/fonts/chinese/MSYHL.TTC: Microsoft YaHei UI,Microsoft YaHei UI Light:style=Light,Regular
/usr/share/fonts/chinese/Songti.ttc: Songti SC:style=Black
/usr/share/fonts/chinese/SIMKAI.TTF: KaiTi:style=Regular,Normaali
/usr/share/fonts/chinese/Songti.ttc: Songti SC,宋体\-简,宋體\-簡:style=Bold,粗体,粗體
/usr/share/fonts/chinese/Songti.ttc: Songti TC,宋体\-繁,宋體\-繁:style=Bold,粗体,粗體
/usr/share/fonts/chinese/STSONG.TTF: STSong:style=Regular
/usr/share/fonts/chinese/仿宋_GB2312.ttf: FangSong_GB2312:style=Regular
/usr/share/fonts/chinese/SIMHEI.TTF: SimHei:style=Normal
/usr/share/fonts/chinese/楷体_GB2312.ttf: KaiTi_GB2312:style=Regular
/usr/share/fonts/chinese/SIMFANG.TTF: FangSong:style=Regular,Normaali
/usr/share/fonts/chinese/MSYHL.TTC: Microsoft YaHei,Microsoft YaHei Light:style=Light,Regular
检查能否解析中文字体名
for family in 微软雅黑 宋体 黑体 仿宋 仿宋_GB2312 楷体 楷体_GB2312 隶书 幼圆; do echo -n "$family: "; fc-match "$family"; done
[root@webadmin01 chinese]# for family in 微软雅黑 宋体 黑体 仿宋 仿宋_GB2312 楷体 楷体_GB2312 隶书 幼圆; do echo -n "$family: "; fc-match "$family"; done
微软雅黑: DejaVuSans.ttf: "DejaVu Sans" "Book"
宋体: SIMSUN.TTC: "SimSun" "Regular"
黑体: DejaVuSans.ttf: "DejaVu Sans" "Book"
仿宋: DejaVuSans.ttf: "DejaVu Sans" "Book"
仿宋_GB2312: DejaVuSans.ttf: "DejaVu Sans" "Book"
楷体: DejaVuSans.ttf: "DejaVu Sans" "Book"
楷体_GB2312: DejaVuSans.ttf: "DejaVu Sans" "Book"
隶书: DejaVuSans.ttf: "DejaVu Sans" "Book"
幼圆: DejaVuSans.ttf: "DejaVu Sans" "Book"
发现不能正常解析中文字体名
配置别名
vim /etc/fonts/fonts.conf
在
微软雅黑
Microsoft YaHei
宋体
SimSun
黑体
SimHei
仿宋
FangSong
仿宋_GB2312
FangSong_GB2312
楷体
KaiTi
楷体_GB2312
KaiTi_GB2312
隶书
LiSu
幼圆
YouYuan
配置后,再次检查解析情况
[root@webadmin01 chinese]# for family in 微软雅黑 宋体 黑体 仿宋 仿宋_GB2312 楷体 楷体_GB2312 隶书 幼圆; do echo -n "$family: "; fc-match "$family"; done
微软雅黑: MSYH.TTC: "Microsoft YaHei" "Normal"
宋体: SIMSUN.TTC: "SimSun" "Regular"
黑体: SIMHEI.TTF: "SimHei" "Normal"
仿宋: SIMFANG.TTF: "FangSong" "Regular"
仿宋_GB2312: 仿宋_GB2312.ttf: "FangSong_GB2312" "Regular"
楷体: SIMKAI.TTF: "KaiTi" "Regular"
楷体_GB2312: 楷体_GB2312.ttf: "KaiTi_GB2312" "Regular"
隶书: 隶书.ttf: "LiSu" "Regular"
幼圆: youyuan.TTF: "YouYuan" "Regular"
总结
- 在网页编写时,css font-family还是尽量用英文字体名称,不要使用中文字体名称。比如这样写:
font-family:Microsoft YaHei,tahoma,arial,Hiragino Sans GB,"\5B8B\4F53",sans-serif
- 在Linux环境,可以通过修改/etc/fonts/fonts.config来配置中文字体解析规则, 比如上面提到的适配“微软雅黑 宋体 黑体 仿宋 仿宋_GB2312 楷体 楷体_GB2312 隶书 幼圆”等这些中文字体名称。
.gz-page-content .content-title .notes {
font-size: 24px;
padding: 14px 0 9px;
margin-bottom: 30px;
line-height: 150%;
font-family: 'FangSong','仿宋', 'SimSun', '宋体';
color: #333333;
}
参考资料
- How To Set Default Fonts and Font Aliases on Linux