linux服务器上word转pdf后乱码问题

问题描述

项目开发中需要将word转化为pdf格式,本机开发测试都没问题,部署到服务器上(linux)系统,转换成pdf后全是乱码。

原因分析

通过搜索资料,发现可能是linux系统上的中文语言包支持不足,导致word中的字体无法被系统识别,进而导致的问题。

解决方案
  • 修复方法
  1. 找到windows系统下的字体库,打包压缩。通常windows系统在这个目录下:C:\Windows\Fonts
  2. 上传到linux下的字体库目录下,通常字体库位于:/usr/share/fonts,在这里创建个目录,用来区别是自己上传的字体库,比如名字叫 chinese;然后把自己windows下打包好的文件传上来,解压到这个目录下;
  3. 让linux系统认识这些新的字体库,并且可以使用,执行这些命令:
bash 复制代码
sudo mkfontscale
sudo mkfontdir
sudo fc-cache -fv

如果遇到安装失败,可以检查下是不是文件的权限有问题,给文件授权:

bash 复制代码
chmod 755 *.ttf

或者

bash 复制代码
chmod 755 *

若提示命令不存在,请手动安装mkfontscale;

  • 验证过程
    执行命令
bash 复制代码
fc-list :lang=zh

显示字体库安装情况:

bash 复制代码
/usr/share/fonts/chinese/方正细等线_GBK.ttf: FZXiDengXian\-Z06:style=Regular
/usr/share/fonts/chinese/方正姚体_GBK.ttf: FZYaoTi\-M06:style=Regular
/usr/share/fonts/chinese/方正黄草_GBK.ttf: FZHuangCao\-S09:style=Regular
/usr/share/fonts/chinese/方正小标宋_GBK.TTF: FZXiaoBiaoSong\-B05:style=Regular
/usr/share/fonts/chinese/方正大标宋_GBK.ttf: FZDaBiaoSong\-B06:style=Regular
/usr/share/fonts/chinese/方正仿宋_GBK.TTF: FZFangSong\-Z02:style=Regular
/usr/share/fonts/chinese/方正隶二_GBK.ttf: FZLiShu II\-S06:style=Regular
/usr/share/fonts/chinese/方正少儿_GBK.ttf: FZShaoEr\-M11:style=Regular
/usr/share/fonts/chinese/方正综艺_GBK.ttf: FZZongYi\-M05:style=Regular
/usr/share/fonts/chinese/方正舒体__GBK.ttf: FZShuTi\-S05:style=Regular
/usr/share/fonts/chinese/方正稚艺_GBK.ttf: FZZhiYi\-M12:style=Regular
/usr/share/fonts/chinese/方正隶变_GBK.TTF: FZLiBian\-S02:style=Regular
/usr/share/fonts/chinese/msyh.ttc: Microsoft YaHei:style=Normal
/usr/share/fonts/chinese/方正魏碑_GBK.ttf: FZWeiBei\-S03:style=Regular
/usr/share/fonts/chinese/方正彩云_GBK.ttf: FZCaiYun\-M09:style=Regular
/usr/share/fonts/chinese/方正粗圆_GBK.ttf: FZCuYuan\-M03:style=Regular
/usr/share/fonts/chinese/方正康体_GBK.ttf: FZKangTi\-S07:style=Regular
/usr/share/fonts/chinese/simsun.ttc: SimSun,宋体:style=Regular,常规
/usr/share/fonts/chinese/方正书宋_GBK.TTF: FZShuSong\-Z01:style=Regular
/usr/share/fonts/chinese/方正细圆_GBK.TTF: FZXiYuan\-M01:style=Regular
/usr/share/fonts/chinese/方正大黑_GBK.ttf: FZDaHei\-B02:style=Regular
/usr/share/fonts/chinese/方正宋一_GBK.TTF: FZSongYi\-Z13:style=Regular
/usr/share/fonts/chinese/msyhbd.ttc: Microsoft YaHei:style=Έντονα
/usr/share/fonts/chinese/方正新舒体_GBK.ttf: FZNew ShuTi\-S08:style=Regular
/usr/share/fonts/chinese/方正粗宋_GBK.ttf: FZCuSong\-B09:style=Regular
/usr/share/fonts/chinese/Dengl.ttf: DengXian,DengXian Light:style=Light,Regular
/usr/share/fonts/chinese/方正华隶_GBK.ttf: FZHuaLi\-M14:style=Regular
/usr/share/fonts/chinese/方正粗倩_GBK.ttf: FZCuQian\-M17:style=Regular
/usr/share/fonts/chinese/方正水柱_GBK.ttf: FZShuiZhu\-M08:style=Regular
/usr/share/fonts/chinese/方正平和_GBK.ttf: FZPingHe\-S11:style=Regular
/usr/share/fonts/chinese/Deng.ttf: DengXian:style=Regular
/usr/share/fonts/chinese/msyh.ttc: Microsoft YaHei UI:style=Normal
/usr/share/fonts/chinese/方正细珊瑚_GBK.ttf: FZXiShanHu\-M13:style=Regular
/usr/share/fonts/chinese/msyhbd.ttc: Microsoft YaHei UI:style=Έντονα
/usr/share/fonts/chinese/方正细黑一_GBK.TTF: FZXiHei I\-Z08:style=Regular
/usr/share/fonts/chinese/方正胖娃_GBK.ttf: FZPangWa\-M18:style=Regular
/usr/share/fonts/chinese/Dengb.ttf: DengXian:style=Bold
/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/方正隶书_GBK.ttf: FZLiShu\-S01:style=Regular
/usr/share/fonts/chinese/方正中等线_GBK.TTF: FZZhongDengXian\-Z07:style=Regular
/usr/share/fonts/chinese/方正准圆_GBK.TTF: FZZhunYuan\-M02:style=Regular
/usr/share/fonts/chinese/msjhbd.ttc: Microsoft JhengHei:style=Félkövér
/usr/share/fonts/chinese/方正新报宋_GBK.ttf: FZNew BaoSong\-Z12:style=Regular
/usr/share/fonts/chinese/方正楷体_GBK.TTF: FZKai\-Z03:style=Regular    

已经可以看到这些常见的word字体了。

很重要的最后一步

重启服务器!!!
重启服务器!!!
重启服务器!!!

重启前记得先看下有哪些应用在上面,因为重启后,这些应用都要启动起来。

相关推荐
vortex515 小时前
fd 工具指南:find 的现代替代品
linux·运维开发·命令行工具
馨谙16 小时前
vim保姆级使用,操作详解,快捷键大全总结
linux·编辑器·vim
驱动探索者16 小时前
find 命令使用介绍
java·linux·运维·服务器·前端·学习·microsoft
半路_出家ren16 小时前
IPTables防火墙
服务器·网络·iptables
BruceD_16 小时前
新装 CentOS 7 切换 yum 源完整指南
linux·python·docker·centos·yum
洋哥网络科技16 小时前
Centos系统替代选择
linux·运维·centos
礼拜天没时间.16 小时前
VMware安装虚拟机并且部署 CentOS 7 指南
linux·运维·centos·系统安装
de之梦-御风16 小时前
【MediaMTX】centos 7 安装MediaMTX
linux·运维·centos
领创工作室17 小时前
安卓设备分区作用详解-测试机红米K40
android·java·linux
小晶晶京京17 小时前
day54-Zabbix(第三部分)
linux·运维·服务器·zabbix