Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
T
travel-cloud
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
cloud
travel-cloud
Commits
a65b9634
提交
a65b9634
authored
5月 27, 2025
作者:
hzh
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
水印修复
上级
039e2cc5
显示空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
14 行增加
和
8 行删除
+14
-8
WatermarkUtil.java
...ava/org/dromara/common/core/utils/file/WatermarkUtil.java
+2
-2
PdfWatermarkProcessor.java
...utils/file/watermark/processor/PdfWatermarkProcessor.java
+12
-6
没有找到文件。
ruoyi-common/ruoyi-common-core/src/main/java/org/dromara/common/core/utils/file/WatermarkUtil.java
浏览文件 @
a65b9634
...
@@ -123,8 +123,8 @@ public class WatermarkUtil {
...
@@ -123,8 +123,8 @@ public class WatermarkUtil {
File
pdfOutputFile
=
FileUtil
.
touch
(
FileUtils
.
addFolderBeforeFileName
(
pdfFile
.
getPath
(),
"watermark"
));
File
pdfOutputFile
=
FileUtil
.
touch
(
FileUtils
.
addFolderBeforeFileName
(
pdfFile
.
getPath
(),
"watermark"
));
// 配置PDF水印参数
// 配置PDF水印参数
WatermarkConfig
pdfConfig
=
new
WatermarkConfig
.
Builder
()
WatermarkConfig
pdfConfig
=
new
WatermarkConfig
.
Builder
()
.
watermarkText
(
"测试水印
PDF
"
)
.
watermarkText
(
"测试水印"
)
.
fontName
(
getFontName
(
pdfFile
.
getPath
(),
"测试水印
PDF
"
))
.
fontName
(
getFontName
(
pdfFile
.
getPath
(),
"测试水印"
))
.
fontSize
(
30
)
.
fontSize
(
30
)
.
color
(
Color
.
RED
)
.
color
(
Color
.
RED
)
.
alpha
(
0.3f
)
.
alpha
(
0.3f
)
...
...
ruoyi-common/ruoyi-common-core/src/main/java/org/dromara/common/core/utils/file/watermark/processor/PdfWatermarkProcessor.java
浏览文件 @
a65b9634
package
org
.
dromara
.
common
.
core
.
utils
.
file
.
watermark
.
processor
;
package
org
.
dromara
.
common
.
core
.
utils
.
file
.
watermark
.
processor
;
import
cn.hutool.core.io.FileUtil
;
import
com.itextpdf.text.BaseColor
;
import
com.itextpdf.text.BaseColor
;
import
com.itextpdf.text.DocumentException
;
import
com.itextpdf.text.DocumentException
;
import
com.itextpdf.text.Element
;
import
com.itextpdf.text.Element
;
...
@@ -134,14 +135,19 @@ public class PdfWatermarkProcessor implements WatermarkProcessor {
...
@@ -134,14 +135,19 @@ public class PdfWatermarkProcessor implements WatermarkProcessor {
}
else
if
(
osName
.
contains
(
"mac"
))
{
}
else
if
(
osName
.
contains
(
"mac"
))
{
fontPath
=
"/Library/Fonts/"
+
fontName
+
".ttf"
;
fontPath
=
"/Library/Fonts/"
+
fontName
+
".ttf"
;
}
else
if
(
osName
.
contains
(
"linux"
))
{
}
else
if
(
osName
.
contains
(
"linux"
))
{
fontPath
=
"/usr/share/fonts/truetype/"
+
fontName
+
".ttf"
;
// Linux下尝试多个路径
String
[]
paths
=
{
"/usr/share/fonts/truetype/"
+
fontName
+
".ttf"
,
"/usr/share/fonts/opentype/"
+
fontName
+
".ttf"
,
"/usr/local/share/fonts/"
+
fontName
+
".ttf"
};
for
(
String
path
:
paths
)
{
if
(
FileUtil
.
exist
(
path
))
{
return
path
;
}
}
// 检查文件是否存在
if
(
fontPath
!=
null
&&
new
File
(
fontPath
).
exists
())
{
return
fontPath
;
}
}
return
paths
[
0
];
}
return
null
;
return
null
;
}
}
}
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论