解决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
  • 博文不易,辛苦各位猿友点个关注和赞,然后评论区留邮箱,看到后第一时间发
  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
使用Linux平台上的Java编程语言实现给图片上文字水印,将文文字展示为方框形状的步骤如下: 1. 首先,确保系统环境已经安装了Java开发工具(JDK)和相关的库文件。 2. 在Java代码引入相关的图像处理库,例如Java提供的AWT和Java 2D库。 3. 载待添水印图片文件。可以使用Java IO库的相关类,如ImageIO类,来读取和处理图片文件。 4. 创建一个新的图片对象,以便在其上添水印。可以使用BufferedImage类来创建一个空白的图片对象,并设置其大小和颜色模式。 5. 根据读取的图片文件,将其内容绘制到新的图片对象。可以使用Java 2D库的Graphics类和Graphics2D类来实现这一步骤。 6. 设计一个方框形状的水印。可以通过Java的字体相关类(如Font、FontMetrics等)来设置合适的字体样式和字号,并计算文字的宽度和高度。 7. 在新的图片对象的指定坐标位置上绘制方框形状的水印。可以使用Java 2D库的绘图方法,如drawRect()函数绘制方框的边框,fillRect()函数填充方框的内部,以及drawString()函数绘制文文字。 8. 最后,将新生成的带有水印图片保存到文件。可以使用ImageIO类的write()函数将图片对象保存为指定的格式(如JPEG、PNG等)的文件。 通过以上步骤,就可以在Linux平台上使用Java编程实现给图片文方框水印的功能了。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小P聊技术

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值