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

很重要的最后一步

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

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

相关推荐
.m16 分钟前
Word怎样转换为PDF
pdf
IPFLY代理专家19 分钟前
Linux设置动态IP的三种方法:图文+命令行实操详解
linux·前端框架
Data-Miner35 分钟前
417页PDF | 2025年“人工智能+”行业标杆案例荟萃
人工智能·pdf
mygugu38 分钟前
Conda install安装了一些库,如何撤销操作
linux·conda
初九之潜龙勿用1 小时前
技术与情感交织的一生 (十一)
服务器·笔记·microsoft·印象笔记
努力做小白1 小时前
Linux驱动25 --- RkMedia音频API使用&&增加 USB 音视频设备
linux·驱动开发·单片机·嵌入式硬件·音视频
明月心9521 小时前
NFS CENTOS系统 安装配置
linux·运维·centos
Raymond运维1 小时前
MySQL 8.0源码编译安装(二)
linux·运维·mysql
xw51 小时前
免费的个人网站托管-InfinityFree
服务器·前端
!win !2 小时前
免费的个人网站托管-InfinityFree
服务器·前端工具