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
ef24d374
Commit
ef24d374
authored
Feb 18, 2025
by
徐俊
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
xujun
parent
82a96eb9
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
74 additions
and
1 deletion
+74
-1
ComProjectDTO.java
...ain/java/com/yiboshi/science/param/dto/ComProjectDTO.java
+3
-0
ProjectInfoToPDF.java
...main/java/com/yiboshi/science/utils/ProjectInfoToPDF.java
+70
-0
ComProjectDAO.xml
science-admin/src/main/resources/mapper/ComProjectDAO.xml
+1
-1
No files found.
science-admin/src/main/java/com/yiboshi/science/param/dto/ComProjectDTO.java
View file @
ef24d374
...
...
@@ -248,6 +248,9 @@ public class ComProjectDTO extends BaseDTO {
/** URL */
@ApiModelProperty
(
value
=
"URL"
,
position
=
7
)
private
String
downloadUrl
;
/** 转换文件URL */
@ApiModelProperty
(
value
=
"转换文件URL"
,
position
=
7
)
private
String
convertUrl
;
/** 单位 */
@ApiModelProperty
(
value
=
"单位"
,
position
=
41
)
...
...
science-admin/src/main/java/com/yiboshi/science/utils/ProjectInfoToPDF.java
View file @
ef24d374
...
...
@@ -13,6 +13,8 @@ import java.util.Objects;
import
java.text.SimpleDateFormat
;
import
java.util.Date
;
import
java.util.List
;
import
java.nio.ByteBuffer
;
import
java.nio.channels.FileChannel
;
public
class
ProjectInfoToPDF
{
...
...
@@ -75,6 +77,11 @@ public class ProjectInfoToPDF {
// 项目经费预算表
addProjectBudgetTable
(
document
,
project
,
bfChinese
,
fsChinese
);
// 插入申请书正文PDF
if
(
project
.
getConvertUrl
()
!=
null
&&
!
project
.
getConvertUrl
().
trim
().
isEmpty
())
{
insertPdfContent
(
document
,
System
.
getProperty
(
"user.dir"
)
+
project
.
getConvertUrl
(),
writer
);
}
// 添加新页面
document
.
newPage
();
...
...
@@ -936,4 +943,67 @@ public class ProjectInfoToPDF {
}
}
}
/**
* 插入PDF文件到指定位置
* @param document 目标文档
* @param pdfPath 要插入的PDF文件路径
* @throws DocumentException
* @throws IOException
*/
private
static
void
insertPdfContent
(
Document
document
,
String
pdfPath
,
PdfWriter
writer
)
throws
DocumentException
,
IOException
{
PdfReader
reader
=
null
;
try
{
// 添加标题
Font
titleFont
=
new
Font
(
BaseFont
.
createFont
(),
12
,
Font
.
BOLD
);
Paragraph
title
=
new
Paragraph
(
"申请书正文"
,
titleFont
);
title
.
setAlignment
(
Element
.
ALIGN_CENTER
);
title
.
setSpacingAfter
(
20
f
);
document
.
add
(
title
);
// 读取PDF文件内容
byte
[]
pdfBytes
=
readPdfToBytes
(
pdfPath
);
// 创建PdfReader
reader
=
new
PdfReader
(
pdfBytes
);
// 获取PDF页数
int
totalPages
=
reader
.
getNumberOfPages
();
// 复制每一页
for
(
int
i
=
1
;
i
<=
totalPages
;
i
++)
{
document
.
newPage
();
PdfImportedPage
page
=
writer
.
getImportedPage
(
reader
,
i
);
PdfContentByte
cb
=
writer
.
getDirectContent
();
cb
.
addTemplate
(
page
,
0
,
0
);
}
}
catch
(
Exception
e
)
{
System
.
out
.
println
(
"插入PDF文件失败: "
+
e
.
getMessage
());
e
.
printStackTrace
();
throw
e
;
// 重新抛出异常以确保错误被正确处理
}
// 不在这里关闭reader,让它在document关闭时自动关闭
}
/**
* 读取PDF文件并返回字节数组
* @param pdfPath PDF文件路径
* @return 字节数组
*/
private
static
byte
[]
readPdfToBytes
(
String
pdfPath
)
throws
IOException
{
File
file
=
new
File
(
pdfPath
);
if
(!
file
.
exists
())
{
throw
new
FileNotFoundException
(
"PDF文件不存在: "
+
pdfPath
);
}
try
(
FileInputStream
fis
=
new
FileInputStream
(
file
))
{
ByteArrayOutputStream
bos
=
new
ByteArrayOutputStream
();
byte
[]
buffer
=
new
byte
[
1024
];
int
bytesRead
;
while
((
bytesRead
=
fis
.
read
(
buffer
))
!=
-
1
)
{
bos
.
write
(
buffer
,
0
,
bytesRead
);
}
return
bos
.
toByteArray
();
}
}
}
science-admin/src/main/resources/mapper/ComProjectDAO.xml
View file @
ef24d374
...
...
@@ -45,7 +45,7 @@
ic.total_funding,ic.gov_funding,ic.unit_funding,ic.self_funding,ic.other_funding,
ic.research_content,ic.technology_target, ic.economy_target, ic.achievement_target, ic.technology_reports_target, ic.other_target,
ic.proj_attribute,ic.remark,ic.year_target,ic.year1_goal,ic.year2_goal,ic.year3_goal,
c.id download_id,c.download_url,c.file_name
c.id download_id,c.download_url,c.
convert_url,c.
file_name
from com_project a
left join com_project_basic ic on a.id=ic.proj_id
left join system_parameter b on a.knowledge_id=b.id and b.type_id=68
...
...
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