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
c45034f8
Commit
c45034f8
authored
Mar 29, 2024
by
盖献康
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'gaixiankang' into 'dev'
检验报告PDF - 模板+代码渲染 See merge request
!242
parents
62b113b8
ed4c8a5a
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
93 additions
and
34 deletions
+93
-34
InspectionReportPdfVO.java
.../main/java/com/ruoyi/domain/vo/InspectionReportPdfVO.java
+5
-0
PdfTemplateManagementServiceImpl.java
.../ruoyi/service/impl/PdfTemplateManagementServiceImpl.java
+79
-31
TaskMapper.xml
quality-review/src/main/resources/mapper/TaskMapper.xml
+2
-1
PdfBaseWriter.java
...n/src/main/java/com/ruoyi/common/utils/PdfBaseWriter.java
+7
-2
No files found.
quality-review/src/main/java/com/ruoyi/domain/vo/InspectionReportPdfVO.java
View file @
c45034f8
...
...
@@ -165,4 +165,9 @@ public class InspectionReportPdfVO {
*/
private
String
brandImage
;
/**
* 样品照片
*/
private
String
samplePhotos
;
}
quality-review/src/main/java/com/ruoyi/service/impl/PdfTemplateManagementServiceImpl.java
View file @
c45034f8
...
...
@@ -25,11 +25,9 @@ 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.net.URL
;
import
java.util.*
;
import
java.util.List
;
...
...
@@ -85,7 +83,7 @@ public class PdfTemplateManagementServiceImpl implements PdfTemplateManagementSe
// 获取表单所有元素
AcroFields
fields
=
ps
.
getAcroFields
();
// 设置具体字体格式的编码, 不设置的话中文可能不会显示
BaseFont
bf
=
BaseFont
.
createFont
(
"
STSongStd-Light"
,
"UniGB-UCS2-H"
,
BaseFont
.
NOT_EMBEDDED
);
BaseFont
bf
=
BaseFont
.
createFont
(
"
/fonts/STSong.TTF"
,
BaseFont
.
IDENTITY_H
,
BaseFont
.
NOT_EMBEDDED
);
fields
.
addSubstitutionFont
(
bf
);
// 测试数据
InspectionReportPdfVO
inspectionReportPdfVO
=
requireData
(
taskId
);
...
...
@@ -97,33 +95,83 @@ public class PdfTemplateManagementServiceImpl implements PdfTemplateManagementSe
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
());
// 把第一个模板填入数据后生成一个oss
String
templateName
=
uploadMinio
(
bos
,
"整车信息安全检验临时模板"
);
// 创建一个空PDF, 融合两个PDF
Document
document
=
new
Document
();
ByteArrayOutputStream
allOut
=
new
ByteArrayOutputStream
();
PdfCopy
copy
=
new
PdfCopy
(
document
,
allOut
);
document
.
open
();
// 第一个PDF
PdfReader
templateReader
=
new
PdfReader
(
minioUrl
()
+
templateName
);
int
numberPage
=
templateReader
.
getNumberOfPages
();
for
(
int
i
=
1
;
i
<
numberPage
;
i
++)
{
PdfImportedPage
importedPage
=
copy
.
getImportedPage
(
templateReader
,
i
);
copy
.
addPage
(
importedPage
);
}
// 第二个PDF
String
codeName
=
getInspectionReportCode
(
inspectionReportPdfVO
);
PdfReader
codeReader
=
new
PdfReader
(
minioUrl
()
+
codeName
);
for
(
int
i
=
1
;
i
<=
codeReader
.
getNumberOfPages
();
i
++)
{
copy
.
addPage
(
copy
.
getImportedPage
(
codeReader
,
i
));
}
document
.
close
();
return
uploadMinio
(
allOut
,
"整车信息安全检验报告-"
+
getReportName
());
}
/**
* 检验报告 - 代码渲染部分
* @param data
* @return
*/
@SneakyThrows
private
String
getInspectionReportCode
(
InspectionReportPdfVO
data
)
{
ByteArrayOutputStream
outputStream
=
new
ByteArrayOutputStream
();
PdfBaseWriter
document
=
new
PdfBaseWriter
(
outputStream
);
document
.
open
();
// 代码渲染
document
.
setParagraph
(
"报告编号:"
+
data
.
getReportNumber
(),
10.5f
,
Element
.
ALIGN_RIGHT
,
0
,
10
f
,
0
f
);
document
.
setParagraph
(
"检 验 报 告"
,
22
f
,
Element
.
ALIGN_CENTER
,
0
,
0
f
,
0
f
);
PdfPTable
signTable
=
new
PdfPTable
(
new
float
[]{
65
,
20
});
signTable
.
setSpacingBefore
(
5
);
signTable
.
setWidthPercentage
(
85
);
document
.
writeBottomCell
(
"共 10 页"
,
Element
.
ALIGN_RIGHT
,
1
,
1
,
signTable
).
setRightIndent
(
30
f
);
document
.
writeBottomCell
(
"第 10 页"
,
Element
.
ALIGN_RIGHT
,
1
,
1
,
signTable
);
document
.
addContent
(
signTable
);
document
.
setParagraph
(
"7.附录"
,
10.5f
,
Element
.
ALIGN_LEFT
,
45
,
1
f
,
0
f
);
document
.
setParagraph
(
"图 1 样品照片"
,
10.5f
,
Element
.
ALIGN_CENTER
,
0
,
20
f
,
0
f
);
// 添加内容到新页面
PdfPTable
pictureTable
=
new
PdfPTable
(
new
float
[]{
25
,
25
,
25
,
25
});
pictureTable
.
setWidthPercentage
(
90
);
pictureTable
.
setSpacingBefore
(
10
);
List
<
String
>
pictureList
=
Arrays
.
asList
(
data
.
getSamplePhotos
().
split
(
","
));
int
result
=
pictureList
.
size
();
while
(
result
%
4
!=
0
)
{
result
++;
}
for
(
int
i
=
0
;
i
<
result
;
i
++)
{
PdfPCell
cell
=
new
PdfPCell
();
cell
.
setBorder
(
Rectangle
.
NO_BORDER
);
Optional
<
String
>
optionalElement
=
i
<
pictureList
.
size
()
?
Optional
.
of
(
pictureList
.
get
(
i
))
:
Optional
.
empty
();
if
(
optionalElement
.
isPresent
())
{
Image
image
=
Image
.
getInstance
(
new
URL
(
minioEndpoint
+
optionalElement
.
get
()));
image
.
scaleAbsolute
(
100
,
100
);
cell
.
addElement
(
image
);
}
else
{
Paragraph
paragraph
=
new
Paragraph
();
cell
.
addElement
(
paragraph
);
}
pictureTable
.
addCell
(
cell
);
}
document
.
addContent
(
pictureTable
);
document
.
setParagraph
(
"图 2 试验照片"
,
10.5f
,
Element
.
ALIGN_CENTER
,
0
,
20
f
,
0
f
);
// 关闭PDF
document
.
close
();
return
uploadMinio
(
outputStream
,
"整车信息安全检验临时代码"
);
}
/**
...
...
quality-review/src/main/resources/mapper/TaskMapper.xml
View file @
c45034f8
...
...
@@ -319,7 +319,8 @@
GROUP_CONCAT(distinct s.identification_code) AS vehicleIdentificationNumber,
t.task_list AS inspectionItem,
DATE_FORMAT(t.create_time, '%Y-%m-%d') AS productionDate,
GROUP_CONCAT(distinct s.trademark) AS brandImage
GROUP_CONCAT(distinct s.trademark) AS brandImage,
GROUP_CONCAT(distinct s.sample_photos) AS samplePhotos
from
t_task t
left join t_task_sample_relation tsr on t.id = tsr.task_id
...
...
ruoyi-common/src/main/java/com/ruoyi/common/utils/PdfBaseWriter.java
View file @
c45034f8
...
...
@@ -20,14 +20,19 @@ import java.util.regex.Pattern;
public
class
PdfBaseWriter
extends
Document
{
// ---------------------------------默认参数---------------------------------
// public final String FONT_NAME_ST_SONG_LIGHT = "STSongStd-Light";
// public final String FONT_ENCODING_UNI_GB_UCS2_H = "UniGB-UCS2-H";
/**
* 中文字体
*/
public
final
String
FONT_NAME_ST_SONG_LIGHT
=
"
STSongStd-Light
"
;
public
final
String
FONT_NAME_ST_SONG_LIGHT
=
"
/fonts/STSong.TTF
"
;
/**
* 中文字体编码
*/
public
final
String
FONT_ENCODING_UNI_GB_UCS2_H
=
"UniGB-UCS2-H"
;
public
final
String
FONT_ENCODING_UNI_GB_UCS2_H
=
BaseFont
.
IDENTITY_H
;
//---------------------------------常用字体/颜色---------------------------------
/**
...
...
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