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

很重要的最后一步

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

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

相关推荐
郝学胜-神的一滴19 小时前
使用现代C++构建高效日志系统的分步指南
服务器·开发语言·c++·程序人生·个人开发
kgduu19 小时前
go-ethereum core之交易索引txIndexer
服务器·数据库·golang
柱子子子子20 小时前
【邪修】linux (ubuntu/fedora/arch/debian) wifi hard blocked解决方法-AX210
linux·网络·ubuntu·debian
大龄Python青年20 小时前
Linux发行版Ubuntu24.04安装教程
linux·ubuntu·1024程序员节
强里秋千墙外道20 小时前
【Linux】ssh升级到最新版本-以ubuntu为例
linux·运维·ssh
QC七哥21 小时前
关于宽带网络下公网地址的理解
服务器·网络
9ilk21 小时前
【仿RabbitMQ的发布订阅式消息队列】--- 介绍
linux·笔记·分布式·后端·rabbitmq
馨谙1 天前
OpenSSH 安全配置核心概念解析
linux·服务器·网络
半桔1 天前
【IO多路转接】IO 多路复用之 select:从接口解析到服务器实战
linux·服务器·c++·github·php
无聊的小坏坏1 天前
从零开始:C++ 线程池 TCP 服务器实战(续篇)
服务器·c++·tcp/ip