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字体了。

很重要的最后一步

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

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

相关推荐
namehu1 小时前
一次因企微域名限制引发的“骚操作”:Nginx 与 FRP 的踩坑排查实录
linux·nginx
云动雨颤1 小时前
Linux下PXE服务器搭建
linux·运维·服务器
源远流长jerry1 小时前
STM32之DMA详解
linux·网络·c++·stm32·单片机·嵌入式硬件
wanhengidc1 小时前
云手机会占用本地手机内存吗?
运维·服务器·网络·安全·智能手机
tianyuanwo1 小时前
技术总结:AArch64架构下Jenkins Agent(RPM容器编译节点)掉线问题分析与排查
java·linux·jenkins
blasit2 小时前
Ubuntu 20.04.6交叉编译得到Ubuntu 16.04.6的可执行文件
linux·运维·ubuntu
林枫依依2 小时前
PDF转图片、图片转PDF(免费)
pdf
qq_546937272 小时前
功能强大的PDF工具箱-- PDF补丁丁,v1.1.0.4657新版本,免费无广告,开箱即用版~
pdf
界面开发小八哥2 小时前
.NET表格控件Spread .NET v18.0——支持富文本、增强PDF导出
信息可视化·pdf·.net·数据可视化·spread .net
轻松Ai享生活2 小时前
详解Linux LVM (Logical Volume Manager)
linux·后端