Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
V
vehicle-quality-review
Project
Project
Details
Activity
Releases
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
王飞
vehicle-quality-review
Commits
9586d22d
Commit
9586d22d
authored
Mar 28, 2024
by
盖献康
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
检验报告 - PDF
parent
6e3f4bce
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
63 additions
and
38 deletions
+63
-38
PdfTemplateManagementServiceImpl.java
.../ruoyi/service/impl/PdfTemplateManagementServiceImpl.java
+63
-38
No files found.
quality-review/src/main/java/com/ruoyi/service/impl/PdfTemplateManagementServiceImpl.java
View file @
9586d22d
...
...
@@ -17,6 +17,7 @@ import com.ruoyi.system.mapper.SysDictDataMapper;
import
io.minio.MinioClient
;
import
io.minio.ObjectWriteArgs
;
import
io.minio.PutObjectArgs
;
import
lombok.SneakyThrows
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.stereotype.Service
;
...
...
@@ -24,8 +25,11 @@ import org.springframework.transaction.annotation.Transactional;
import
java.io.ByteArrayInputStream
;
import
java.io.ByteArrayOutputStream
;
import
java.io.FileOutputStream
;
import
java.io.IOException
;
import
java.lang.reflect.Field
;
import
java.nio.file.Files
;
import
java.nio.file.Paths
;
import
java.util.*
;
import
java.util.List
;
...
...
@@ -64,51 +68,72 @@ public class PdfTemplateManagementServiceImpl implements PdfTemplateManagementSe
* @param taskId
* @return
*/
@SneakyThrows
@Override
public
String
generateInspectionReport
(
Long
taskId
)
throws
Exception
{
public
String
generateInspectionReport
(
Long
taskId
)
{
PdfReader
reader
=
null
;
PdfStamper
ps
=
null
;
ByteArrayOutputStream
bos
=
null
;
try
{
// 模板绝对路径--服务器
String
fileName
=
"/template/receipt_template_03_27.pdf"
;
// 读取现有模板内容
reader
=
new
PdfReader
(
fileName
);
// 创建输出流
bos
=
new
ByteArrayOutputStream
();
// 实例化PdfStamper准备编辑pdf内容
ps
=
new
PdfStamper
(
reader
,
bos
);
// 获取表单所有元素
AcroFields
fields
=
ps
.
getAcroFields
();
// 设置具体字体格式的编码, 不设置的话中文可能不会显示
BaseFont
bf
=
BaseFont
.
createFont
(
"STSongStd-Light"
,
"UniGB-UCS2-H"
,
BaseFont
.
NOT_EMBEDDED
);
fields
.
addSubstitutionFont
(
bf
);
// 测试数据
InspectionReportPdfVO
inspectionReportPdfVO
=
requireData
(
taskId
);
// 渲染数据
renderData
(
fields
,
inspectionReportPdfVO
,
ps
);
//必须要调用这个,否则文档不会生成的
ps
.
setFormFlattening
(
true
);
ps
.
close
();
}
catch
(
Exception
e
){
e
.
printStackTrace
();
}
finally
{
if
(
bos
!=
null
){
bos
.
close
();
}
if
(
reader
!=
null
){
reader
.
close
();
}
}
assert
bos
!=
null
;
// 名字
// 模板绝对路径--服务器
String
fileName
=
"/template/receipt_template_03_27.pdf"
;
// 读取现有模板内容
reader
=
new
PdfReader
(
fileName
);
// 创建输出流
bos
=
new
ByteArrayOutputStream
();
// 实例化PdfStamper准备编辑pdf内容
ps
=
new
PdfStamper
(
reader
,
bos
);
// 获取表单所有元素
AcroFields
fields
=
ps
.
getAcroFields
();
// 设置具体字体格式的编码, 不设置的话中文可能不会显示
BaseFont
bf
=
BaseFont
.
createFont
(
"STSongStd-Light"
,
"UniGB-UCS2-H"
,
BaseFont
.
NOT_EMBEDDED
);
fields
.
addSubstitutionFont
(
bf
);
// 测试数据
InspectionReportPdfVO
inspectionReportPdfVO
=
requireData
(
taskId
);
// 渲染数据
renderData
(
fields
,
inspectionReportPdfVO
,
ps
);
// 必须要调用这个,否则文档不会生成的
ps
.
setFormFlattening
(
true
);
// 关闭
ps
.
close
();
bos
.
close
();
reader
.
close
();
// // 把第一个模板填入数据后生成一个oss
// String templateName = uploadMinio(bos, "整车信息安全检验临时模板");
// // 创建一个空PDF, 融合两个PDF
// Document document = new Document();
// ByteArrayOutputStream out = new ByteArrayOutputStream();
// PdfCopy copy = new PdfCopy(document, out);
// document.open();
// // 第一个PDF
// PdfReader readerFirst = new PdfReader(minioUrl() + templateName);
// int numberPage = readerFirst.getNumberOfPages();
// for (int i = 1;i < numberPage;i++) {
// PdfImportedPage importedPage = copy.getImportedPage(readerFirst, i);
// copy.addPage(importedPage);
// }
// // 第二个PDF
// ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
// PdfBaseWriter writer = new PdfBaseWriter(outputStream);
// writer.open();
// // 代码渲染
// writer.setParagraph("企业留档文件", 30f, Element.ALIGN_CENTER, 0,15f, 180f);
// writer.close();
// String codeName = uploadMinio(outputStream, "整车信息安全检验临时代码");
// PdfReader pr = new PdfReader(minioUrl() + codeName);
// copy.addPage(copy.getImportedPage(pr, 1));
// document.close();
return
uploadMinio
(
bos
,
"整车信息安全检验报告-"
+
getReportName
());
}
/**
* minio对象存储查看图片地址
* @return
*/
private
String
minioUrl
()
{
return
minioEndpoint
+
"/"
+
bucketName
+
"/"
;
}
private
String
getReportName
()
{
return
DateUtils
.
parseDateToStr
(
"yyyyMMddHHmm"
,
new
Date
());
}
...
...
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