Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
T
travel-cloud
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
cloud
travel-cloud
Commits
c8bc53f5
提交
c8bc53f5
authored
5月 27, 2025
作者:
hzh
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
水印修复
上级
a65b9634
显示空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
4 行增加
和
40 行删除
+4
-40
WatermarkUtil.java
...ava/org/dromara/common/core/utils/file/WatermarkUtil.java
+3
-39
PdfWatermarkProcessor.java
...utils/file/watermark/processor/PdfWatermarkProcessor.java
+1
-1
没有找到文件。
ruoyi-common/ruoyi-common-core/src/main/java/org/dromara/common/core/utils/file/WatermarkUtil.java
浏览文件 @
c8bc53f5
...
...
@@ -10,10 +10,6 @@ import org.dromara.common.core.utils.file.watermark.processor.PdfWatermarkProces
import
java.awt.*
;
import
java.io.File
;
import
java.io.IOException
;
import
java.nio.file.Files
;
import
java.nio.file.Path
;
import
java.nio.file.Paths
;
import
java.util.HashMap
;
import
java.util.Map
;
...
...
@@ -70,7 +66,7 @@ public class WatermarkUtil {
// 获取文件扩展名
String
extension
=
getFileExtension
(
path
).
toLowerCase
();
if
(
StringUtils
.
equals
(
extension
,
"pdf"
))
{
return
watermarkText
.
codePoints
().
anyMatch
(
c
->
Character
.
UnicodeScript
.
of
(
c
)
==
Character
.
UnicodeScript
.
HAN
)
?
"
SimHei"
:
"A
rial"
;
return
watermarkText
.
codePoints
().
anyMatch
(
c
->
Character
.
UnicodeScript
.
of
(
c
)
==
Character
.
UnicodeScript
.
HAN
)
?
"
simhei"
:
"a
rial"
;
}
else
{
return
"宋体"
;
}
...
...
@@ -86,45 +82,13 @@ public class WatermarkUtil {
public
static
void
main
(
String
[]
args
)
{
// 示例:给图片添加水印
Path
sourceImagePath
=
Paths
.
get
(
"D:\\1.jpg"
);
Path
targetImagePath
=
Paths
.
get
(
"D:\\output.jpg"
);
// 配置水印参数
WatermarkConfig
imageConfig
=
new
WatermarkConfig
.
Builder
()
.
watermarkText
(
"测试水印PDF"
)
.
fontName
(
getFontName
(
sourceImagePath
.
toFile
().
getPath
(),
"测试水印PDF"
))
.
fontSize
(
30
)
.
color
(
Color
.
RED
)
.
alpha
(
0.5f
)
.
angle
(
30
)
.
build
();
// 验证源文件是否存在
if
(!
Files
.
exists
(
sourceImagePath
))
{
System
.
err
.
println
(
"源文件不存在: "
+
sourceImagePath
);
return
;
}
// 确保目标目录存在
try
{
Files
.
createDirectories
(
targetImagePath
.
getParent
());
}
catch
(
IOException
e
)
{
System
.
err
.
println
(
"无法创建目标目录: "
+
e
.
getMessage
());
return
;
}
addTextWatermark
(
sourceImagePath
.
toFile
(),
targetImagePath
.
toFile
(),
imageConfig
);
// 示例:给PDF添加水印
File
pdfFile
=
new
File
(
"C:\\Users\\wenhe\\Downloads\\安盛保险-卓越个人基础版.pdf"
);
File
pdfOutputFile
=
FileUtil
.
touch
(
FileUtils
.
addFolderBeforeFileName
(
pdfFile
.
getPath
(),
"watermark"
));
// 配置PDF水印参数
WatermarkConfig
pdfConfig
=
new
WatermarkConfig
.
Builder
()
.
watermarkText
(
"
测试水印
"
)
.
fontName
(
getFontName
(
pdfFile
.
getPath
(),
"
测试水印
"
))
.
watermarkText
(
"
PDF
"
)
.
fontName
(
getFontName
(
pdfFile
.
getPath
(),
"
PDF
"
))
.
fontSize
(
30
)
.
color
(
Color
.
RED
)
.
alpha
(
0.3f
)
...
...
ruoyi-common/ruoyi-common-core/src/main/java/org/dromara/common/core/utils/file/watermark/processor/PdfWatermarkProcessor.java
浏览文件 @
c8bc53f5
...
...
@@ -148,6 +148,6 @@ public class PdfWatermarkProcessor implements WatermarkProcessor {
}
return
paths
[
0
];
}
return
null
;
return
fontPath
;
}
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论