解决Linux下图片水印乱码以及生成PDF乱码问题

1 问题定位

windows下面无问题,在linux下面出现问题,中文变成方框,经过排查发现linux下缺少字体,只需将widows字体上传到linux服务器进行配置加载就好

2 解决方案

2.1 方案一

2.1.1 安装字体库

[root@localhost ~]# yum -y install fontconfig

2.1.2 新建目录

[root@localhost ~]# /usr/share/fonts
[root@localhost fonts]# mkdir chinese
[root@localhost ~]# cd chinese

2.1.2 上传Windows字体文件

将C:\Windows\Fonts下面的所有文件,上传到服务器的/usr/share/fonts/chinese目录下

[root@localhost chinese]# ll
total 185340
-rwxr-xr-x 1 root root 980756 Jan 20 16:10 arialbd.ttf
-rwxr-xr-x 1 root root 721144 Jan 20 16:10 arialbi.ttf
-rwxr-xr-x 1 root root 717428 Jan 20 16:10 ariali.ttf
-rwxr-xr-x 1 root root 1036584 Jan 20 16:10 arial.ttf
-rwxr-xr-x 1 root root 167592 Jan 20 16:10 ariblk.ttf
-rwxr-xr-x 1 root root 40340 Jan 20 16:10 Arvo-Regular.ttf
-rwxr-xr-x 1 root root 131660 Jan 20 16:10 AxureHandwriting-BoldItalic.otf
-rwxr-xr-x 1 root root 138388 Jan 20 16:10 AxureHandwriting-Bold.otf
-rwxr-xr-x 1 root root 68244 Jan 20 16:10 AxureHandwriting-Italic.otf
-rwxr-xr-x 1 root root 64288 Jan 20 16:10 AxureHandwriting.otf
-rwxr-xr-x 1 root root 322864 Jan 20 16:10 bahnschrift.ttf
-rwxr-xr-x 1 root root 229408 Jan 20 16:10 comicbd.ttf
...

2.1.3 安装字体

[root@localhost chinese]# yum -y install ttmkfdir 

2.1.4 刷新字体缓存

进行这个操作之后,就不用重启机器

[root@localhost chinese]# fc-cache

2.1.5 查看安装字体

[root@localhost ~]# fc-list
/usr/share/fonts/chinese/cour.ttf: Courier New:style=Standaard,Regular
/usr/share/fonts/chinese/consolai.ttf: Consolas:style=Italic
/usr/share/fonts/chinese/monbaiti.ttf: Mongolian Baiti:style=Regular
/usr/share/fonts/chinese/georgiai.ttf: Georgia:style=Italic,Cursiva
/usr/share/fonts/chinese/impact.ttf: Impact:style=Regular,Standard
/usr/share/fonts/chinese/PoiretOne-Regular.ttf: Poiret One:style=Regular
/usr/share/fonts/chinese/palabi.ttf: Palatino Linotype:style=Negreta cursiva,Bold Italic
/usr/share/fonts/chinese/ntailu.ttf: Microsoft New Tai Lue:style=Regular
/usr/share/fonts/chinese/himalaya.ttf: Microsoft Himalaya:style=Regular
/usr/share/fonts/chinese/Roboto-Regular.ttf: Roboto:style=Regular
/usr/share/fonts/chinese/LucidaBrightRegular.ttf: Lucida Bright:style=Regular
/usr/share/fonts/chinese/phagspa.ttf: Microsoft PhagsPa:style=Regular
/usr/share/fonts/chinese/trebucbd.ttf: Trebuchet MS:style=Bold,Negrita
/usr/share/fonts/chinese/gadugi.ttf: Gadugi:style=Regular
/usr/share/fonts/chinese/palai.ttf: Palatino Linotype:style=Cursiva,Italic
/usr/share/fonts/chinese/bahnschrift.ttf: Bahnschrift:style=Bold SemiCondensed
/usr/share/fonts/chinese/bahnschrift.ttf: Bahnschrift:style=Light
/usr/share/fonts/chinese/bahnschrift.ttf: Bahnschrift:style=SemiLight SemiCondensed
/usr/share/fonts/chinese/ntailub.ttf: Microsoft New Tai Lue:style=Bold
/usr/share/fonts/chinese/consola.ttf: Consolas:style=Regular
/usr/share/fonts/chinese/ariali.ttf: Arial:style=Πλάγια,Italic
/usr/share/fonts/chinese/bahnschrift.ttf: Bahnschrift:style=Bold Condensed
...

2.2 方案二

2.2.1 JDK目录

JDK目录 /opt/module/jdk1.8.0_144

[root@localhost jre]# echo $JAVA_HOME
/opt/module/
[root@localhost jre]# cd /opt/module/
[root@localhost module]# ll
total 12
drwxr-xr-x 7 root root 4096 Jul 22 2017 jdk1.8.0_144
[root@localhost module]#

2.2.2 创建目录

[root@localhost jre]# cd /opt/module/jdk1.8.0_144/jre/lib/fonts
[root@localhost fonts]# mkdir fallback
[root@localhost fonts]# cd fallback

2.2.3 上传Windows字体文件

将C:\Windows\Fonts下面的所有文件,上传到服务器的/opt/module/jdk1.8.0_144/jre/lib/fonts/fallback目录下

[root@localhost fallback]# ll
total 185340
-rwxr-xr-x 1 root root 980756 Jan 20 16:10 arialbd.ttf
-rwxr-xr-x 1 root root 721144 Jan 20 16:10 arialbi.ttf
-rwxr-xr-x 1 root root 717428 Jan 20 16:10 ariali.ttf
-rwxr-xr-x 1 root root 1036584 Jan 20 16:10 arial.ttf
-rwxr-xr-x 1 root root 167592 Jan 20 16:10 ariblk.ttf
-rwxr-xr-x 1 root root 40340 Jan 20 16:10 Arvo-Regular.ttf
-rwxr-xr-x 1 root root 131660 Jan 20 16:10 AxureHandwriting-BoldItalic.otf
-rwxr-xr-x 1 root root 138388 Jan 20 16:10 AxureHandwriting-Bold.otf
-rwxr-xr-x 1 root root 68244 Jan 20 16:10 AxureHandwriting-Italic.otf
-rwxr-xr-x 1 root root 64288 Jan 20 16:10 AxureHandwriting.otf
-rwxr-xr-x 1 root root 322864 Jan 20 16:10 bahnschrift.ttf
-rwxr-xr-x 1 root root 229408 Jan 20 16:10 comicbd.ttf

2.3 方案三

如果能确定项目中使用的字体对应的字体文件,只需上传单个文件,比如宋体 对应的字体文件就是 simsun.ttc,这样只需操作一个文件的上传就可以完成问题解决

3 重启服务

重启应用服务,比如tomcat等

4 相关资源

  • 下载地址 https://download.csdn.net/download/qq_15769939/14901213
  • 感谢老铁们点个关注,然后评论区留邮箱,看到后第一时间发

你可能感兴趣的:(解决Linux下图片水印乱码以及生成PDF乱码问题)