Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
amos-boot-biz
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
项目统一框架
amos-boot-biz
Commits
d1f77a6f
Commit
d1f77a6f
authored
Feb 27, 2024
by
suhuiguang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
1.删除无用代码
parent
2daba24c
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
9 additions
and
17 deletions
+9
-17
PdfServiceImpl.java
.../amos/boot/module/jg/biz/service/impl/PdfServiceImpl.java
+5
-10
PdfUtils.java
...a/com/yeejoin/amos/boot/module/jg/biz/utils/PdfUtils.java
+4
-7
No files found.
amos-boot-system-tzs/amos-boot-module-jg/amos-boot-module-jg-biz/src/main/java/com/yeejoin/amos/boot/module/jg/biz/service/impl/PdfServiceImpl.java
View file @
d1f77a6f
...
@@ -33,7 +33,7 @@ public class PdfServiceImpl implements IPdfService {
...
@@ -33,7 +33,7 @@ public class PdfServiceImpl implements IPdfService {
File
imageFile
=
null
,
file
=
null
;
File
imageFile
=
null
,
file
=
null
;
try
{
try
{
imageFile
=
File
.
createTempFile
(
"temp"
,
".png"
);
imageFile
=
File
.
createTempFile
(
"temp"
,
".png"
);
PdfUtils
.
generatorImageWithText
(
imageFile
,
100
,
50
,
text
,
Color
.
RED
);
PdfUtils
.
generatorImageWithText
(
imageFile
,
100
,
50
,
text
,
Color
.
RED
);
file
=
PdfUtils
.
addImageToPdf
(
filePath
,
100
,
50
,
imageFile
.
getAbsolutePath
());
file
=
PdfUtils
.
addImageToPdf
(
filePath
,
100
,
50
,
imageFile
.
getAbsolutePath
());
String
fileName
=
extractFileNameFromPath
(
inputPdfPath
);
String
fileName
=
extractFileNameFromPath
(
inputPdfPath
);
MultipartFile
mockMultipartFile
=
new
MockMultipartFile
(
fileName
,
fileName
,
ContentType
.
APPLICATION_OCTET_STREAM
.
toString
(),
new
FileInputStream
(
file
));
MultipartFile
mockMultipartFile
=
new
MockMultipartFile
(
fileName
,
fileName
,
ContentType
.
APPLICATION_OCTET_STREAM
.
toString
(),
new
FileInputStream
(
file
));
...
@@ -45,10 +45,10 @@ public class PdfServiceImpl implements IPdfService {
...
@@ -45,10 +45,10 @@ public class PdfServiceImpl implements IPdfService {
}
catch
(
IOException
e
)
{
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
e
.
printStackTrace
();
}
finally
{
}
finally
{
if
(
imageFile
!=
null
)
{
if
(
imageFile
!=
null
)
{
imageFile
.
deleteOnExit
();
imageFile
.
deleteOnExit
();
}
}
if
(
file
!=
null
)
{
if
(
file
!=
null
)
{
file
.
deleteOnExit
();
file
.
deleteOnExit
();
}
}
}
}
...
@@ -59,10 +59,8 @@ public class PdfServiceImpl implements IPdfService {
...
@@ -59,10 +59,8 @@ public class PdfServiceImpl implements IPdfService {
public
String
signToPdfWaterPrint
(
String
inputPdfPath
,
String
text
)
{
public
String
signToPdfWaterPrint
(
String
inputPdfPath
,
String
text
)
{
String
newFilePath
=
""
;
String
newFilePath
=
""
;
String
filePath
=
fileServerUrl
+
inputPdfPath
;
String
filePath
=
fileServerUrl
+
inputPdfPath
;
File
imageFile
=
null
,
file
=
null
;
File
file
=
null
;
try
{
try
{
imageFile
=
File
.
createTempFile
(
"temp"
,
".png"
);
PdfUtils
.
generatorImageWithText
(
imageFile
,
200
,
100
,
text
,
Color
.
RED
);
file
=
PdfUtils
.
addFullPageWatermark
(
filePath
,
"已作废"
);
file
=
PdfUtils
.
addFullPageWatermark
(
filePath
,
"已作废"
);
String
fileName
=
extractFileNameFromPath
(
inputPdfPath
);
String
fileName
=
extractFileNameFromPath
(
inputPdfPath
);
MultipartFile
mockMultipartFile
=
new
MockMultipartFile
(
fileName
,
fileName
,
ContentType
.
APPLICATION_OCTET_STREAM
.
toString
(),
new
FileInputStream
(
file
));
MultipartFile
mockMultipartFile
=
new
MockMultipartFile
(
fileName
,
fileName
,
ContentType
.
APPLICATION_OCTET_STREAM
.
toString
(),
new
FileInputStream
(
file
));
...
@@ -74,10 +72,7 @@ public class PdfServiceImpl implements IPdfService {
...
@@ -74,10 +72,7 @@ public class PdfServiceImpl implements IPdfService {
}
catch
(
IOException
e
)
{
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
e
.
printStackTrace
();
}
finally
{
}
finally
{
if
(
imageFile
!=
null
){
if
(
file
!=
null
)
{
imageFile
.
deleteOnExit
();
}
if
(
file
!=
null
){
file
.
deleteOnExit
();
file
.
deleteOnExit
();
}
}
}
}
...
...
amos-boot-system-tzs/amos-boot-module-jg/amos-boot-module-jg-biz/src/main/java/com/yeejoin/amos/boot/module/jg/biz/utils/PdfUtils.java
View file @
d1f77a6f
...
@@ -93,13 +93,10 @@ public class PdfUtils {
...
@@ -93,13 +93,10 @@ public class PdfUtils {
outputPdfFile
=
File
.
createTempFile
(
"output"
,
".pdf"
);
outputPdfFile
=
File
.
createTempFile
(
"output"
,
".pdf"
);
reader
=
new
PdfReader
(
src
);
reader
=
new
PdfReader
(
src
);
stamper
=
new
PdfStamper
(
reader
,
new
FileOutputStream
(
outputPdfFile
));
stamper
=
new
PdfStamper
(
reader
,
new
FileOutputStream
(
outputPdfFile
));
stamper
.
setFormFlattening
(
true
);
PdfGState
gs
=
new
PdfGState
();
PdfGState
gs
=
new
PdfGState
();
// 设置透明度为0.1
// 设置透明度为0.1
gs
.
setFillOpacity
(
0.2f
);
gs
.
setFillOpacity
(
0.2f
);
int
n
=
reader
.
getNumberOfPages
();
int
n
=
reader
.
getNumberOfPages
();
// 创建一个BaseFont实例,用于水印文本
// 创建一个BaseFont实例,用于水印文本
BaseFont
bf
=
BaseFont
.
createFont
(
"STSong-Light"
,
"UniGB-UCS2-H"
,
BaseFont
.
EMBEDDED
);
BaseFont
bf
=
BaseFont
.
createFont
(
"STSong-Light"
,
"UniGB-UCS2-H"
,
BaseFont
.
EMBEDDED
);
// 设置水印文本大小
// 设置水印文本大小
...
@@ -110,8 +107,7 @@ public class PdfUtils {
...
@@ -110,8 +107,7 @@ public class PdfUtils {
float
x
=
0
;
float
x
=
0
;
// 遍历PDF的每一页
// 遍历PDF的每一页
for
(
int
i
=
1
;
i
<=
n
;
i
++)
{
for
(
int
i
=
1
;
i
<=
n
;
i
++)
{
PdfContentByte
over
=
stamper
.
getUnderContent
(
i
);
PdfContentByte
over
=
stamper
.
getOverContent
(
i
);
// 获取页面尺寸
// 获取页面尺寸
Rectangle
pageSize
=
reader
.
getPageSizeWithRotation
(
i
);
Rectangle
pageSize
=
reader
.
getPageSizeWithRotation
(
i
);
float
pageWidth
=
pageSize
.
getWidth
();
float
pageWidth
=
pageSize
.
getWidth
();
...
@@ -119,10 +115,8 @@ public class PdfUtils {
...
@@ -119,10 +115,8 @@ public class PdfUtils {
// 从页面底部开始
// 从页面底部开始
float
y
=
pageHeight
;
float
y
=
pageHeight
;
// 计算文本宽度
// 计算文本宽度
float
textWidth
=
bf
.
getWidthPoint
(
watermarkText
,
fontSize
);
float
textWidth
=
bf
.
getWidthPoint
(
watermarkText
,
fontSize
);
// 添加水印文本到页面
// 添加水印文本到页面
while
(
y
>
0
)
{
while
(
y
>
0
)
{
// 文本从页面左侧开始
// 文本从页面左侧开始
...
@@ -133,6 +127,8 @@ public class PdfUtils {
...
@@ -133,6 +127,8 @@ public class PdfUtils {
//水印颜色
//水印颜色
over
.
setColorFill
(
BaseColor
.
BLACK
);
over
.
setColorFill
(
BaseColor
.
BLACK
);
over
.
setGState
(
gs
);
over
.
setGState
(
gs
);
// 设置文本渲染模式为填充,使文本不可选择
over
.
setTextRenderingMode
(
PdfContentByte
.
TEXT_RENDER_MODE_FILL
);
over
.
setTextMatrix
(
x
,
y
);
over
.
setTextMatrix
(
x
,
y
);
over
.
showTextAligned
(
Element
.
ALIGN_CENTER
,
watermarkText
,
x
,
y
,
45
);
over
.
showTextAligned
(
Element
.
ALIGN_CENTER
,
watermarkText
,
x
,
y
,
45
);
over
.
endText
();
over
.
endText
();
...
@@ -156,4 +152,5 @@ public class PdfUtils {
...
@@ -156,4 +152,5 @@ public class PdfUtils {
return
outputPdfFile
;
return
outputPdfFile
;
}
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment