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
75ae2ca5
Commit
75ae2ca5
authored
Feb 12, 2025
by
徐俊
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
xujun
parent
1c17fb46
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
9 additions
and
3 deletions
+9
-3
ProjectInfoToPDF.java
...main/java/com/yiboshi/science/utils/ProjectInfoToPDF.java
+9
-3
No files found.
science-admin/src/main/java/com/yiboshi/science/utils/ProjectInfoToPDF.java
View file @
75ae2ca5
...
...
@@ -77,6 +77,7 @@ public class ProjectInfoToPDF {
/**
* 加载中文字体
* @param fontPath 字体文件路径(相对于resources目录)
* @return BaseFont 中文字体
* @throws RuntimeException 加载字体失败时抛出异常
*/
...
...
@@ -85,11 +86,16 @@ public class ProjectInfoToPDF {
// 从资源文件夹加载字体
InputStream
fontStream
=
ProjectInfoToPDF
.
class
.
getResourceAsStream
(
fontPath
);
if
(
fontStream
==
null
)
{
throw
new
FileNotFoundException
(
"
在resources/fonts目录下未找到simsun.ttc字体文件"
);
throw
new
FileNotFoundException
(
"
找不到字体文件:"
+
fontPath
);
}
// 获取文件名作为临时文件的前缀
String
fileName
=
fontPath
.
substring
(
fontPath
.
lastIndexOf
(
'/'
)
+
1
);
String
prefix
=
fileName
.
substring
(
0
,
fileName
.
lastIndexOf
(
'.'
));
String
suffix
=
fileName
.
substring
(
fileName
.
lastIndexOf
(
'.'
));
// 将字体文件复制到临时文件
File
tempFile
=
File
.
createTempFile
(
"simsun"
,
".ttc"
);
File
tempFile
=
File
.
createTempFile
(
prefix
,
suffix
);
tempFile
.
deleteOnExit
();
try
(
FileOutputStream
fos
=
new
FileOutputStream
(
tempFile
))
{
...
...
@@ -102,7 +108,7 @@ public class ProjectInfoToPDF {
return
BaseFont
.
createFont
(
tempFile
.
getAbsolutePath
()
+
",0"
,
BaseFont
.
IDENTITY_H
,
BaseFont
.
EMBEDDED
);
}
catch
(
Exception
e
)
{
throw
new
RuntimeException
(
"加载字体文件失败,请确保resources
/fonts目录下存在simsun.ttc文件
:"
+
e
.
getMessage
(),
e
);
throw
new
RuntimeException
(
"加载字体文件失败,请确保resources
目录下存在字体文件 "
+
fontPath
+
"
:"
+
e
.
getMessage
(),
e
);
}
}
...
...
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