Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
Y
yn-health-science
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
徐俊
yn-health-science
Commits
401dd323
Commit
401dd323
authored
Feb 18, 2025
by
徐俊
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
xujun
parent
ef24d374
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
36 additions
and
11 deletions
+36
-11
ComProjectController.java
...ava/com/yiboshi/science/rest/v1/ComProjectController.java
+23
-6
ProjectInfoToPDF.java
...main/java/com/yiboshi/science/utils/ProjectInfoToPDF.java
+13
-5
No files found.
science-admin/src/main/java/com/yiboshi/science/rest/v1/ComProjectController.java
View file @
401dd323
...
...
@@ -214,15 +214,31 @@ public class ComProjectController extends BaseController<ComProjectService, ComP
return
ResponseDataModel
.
ok
(
comProjectService
.
projectImport
(
list
));
}
@ApiOperation
(
value
=
"项目信息导出
1"
,
httpMethod
=
"POST"
,
notes
=
"项目信息导出1
"
)
@ApiOperation
(
value
=
"项目信息导出
"
,
httpMethod
=
"POST"
,
notes
=
"项目信息导出
"
)
@RequestMapping
(
"/projectExport/{id}"
)
@PostMapping
public
ResponseDataModel
<
String
>
projectExport
(
@PathVariable
String
id
)
throws
DocumentException
,
IOException
{
public
void
projectExport
(
@PathVariable
String
id
)
throws
DocumentException
,
IOException
{
try
{
List
<
SystemParameter
>
list
=
systemParameterService
.
getListByType
(
67
);
ComProjectDTO
dto
=
comProjectService
.
getProjectById
(
id
);
String
outputPath
=
"D:\\申请书和合同书.pdf"
;
ProjectInfoToPDF
.
generateProjectPDF
(
dto
,
outputPath
,
list
);
return
ResponseDataModel
.
ok
(
"项目信息导入成功!"
);
// 生成PDF文件字节数组
byte
[]
pdfBytes
=
ProjectInfoToPDF
.
generateProjectPDF
(
dto
,
list
);
// 设置响应头
response
.
setContentType
(
"application/pdf"
);
String
fileName
=
new
String
((
dto
.
getProjName
()
+
".pdf"
).
getBytes
(
"UTF-8"
),
"ISO-8859-1"
);
response
.
setHeader
(
"Content-Disposition"
,
"attachment; filename="
+
fileName
);
response
.
setContentLength
(
pdfBytes
.
length
);
// 写入响应流
try
(
ServletOutputStream
out
=
response
.
getOutputStream
())
{
out
.
write
(
pdfBytes
);
out
.
flush
();
}
}
catch
(
Exception
e
)
{
response
.
setContentType
(
"text/plain;charset=UTF-8"
);
response
.
getWriter
().
write
(
"导出PDF失败:"
+
e
.
getMessage
());
}
}
}
\ No newline at end of file
science-admin/src/main/java/com/yiboshi/science/utils/ProjectInfoToPDF.java
View file @
401dd323
...
...
@@ -21,11 +21,14 @@ public class ProjectInfoToPDF {
/**
* 生成项目申请书和合同书PDF
* @param project 项目信息
* @
param outputPath 输出路径
* @
return 生成的PDF文件字节数组
*/
public
static
void
generateProjectPDF
(
ComProjectDTO
project
,
String
outputPath
,
List
<
SystemParameter
>
projAttributeList
)
throws
DocumentException
,
IOException
{
public
static
byte
[]
generateProjectPDF
(
ComProjectDTO
project
,
List
<
SystemParameter
>
projAttributeList
)
throws
DocumentException
,
IOException
{
ByteArrayOutputStream
baos
=
new
ByteArrayOutputStream
();
Document
document
=
new
Document
(
PageSize
.
A4
);
PdfWriter
writer
=
PdfWriter
.
getInstance
(
document
,
new
FileOutputStream
(
outputPath
));
PdfWriter
writer
=
PdfWriter
.
getInstance
(
document
,
baos
);
try
{
// 文件水印
String
watermark
=
project
.
getAppNo
();
if
(
project
.
getProjState
()
>=
CommonEnum
.
projState
.
pass
.
getCode
())
{
...
...
@@ -44,8 +47,6 @@ public class ProjectInfoToPDF {
document
.
open
();
Font
normalFont
=
new
Font
(
bfChinese
,
12
,
Font
.
NORMAL
);
Font
boldFont
=
new
Font
(
bfChinese
,
12
,
Font
.
BOLD
);
...
...
@@ -104,6 +105,13 @@ public class ProjectInfoToPDF {
addSignatureSection
(
document
,
normalFont
);
document
.
close
();
return
baos
.
toByteArray
();
}
finally
{
if
(
document
.
isOpen
())
{
document
.
close
();
}
baos
.
close
();
}
}
/**
...
...
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