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
11eff3d6
Commit
11eff3d6
authored
Feb 19, 2025
by
徐俊
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
xujun
parent
6d4e9fbd
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
13 deletions
+24
-13
ProjectInfoToPDF.java
...main/java/com/yiboshi/science/utils/ProjectInfoToPDF.java
+24
-13
No files found.
science-admin/src/main/java/com/yiboshi/science/utils/ProjectInfoToPDF.java
View file @
11eff3d6
...
...
@@ -36,11 +36,11 @@ public class ProjectInfoToPDF {
}
// 宋体
BaseFont
bfChinese
=
loadChineseFont
(
"
/fonts/
simsun.ttc"
);
BaseFont
bfChinese
=
loadChineseFont
(
"simsun.ttc"
);
// 仿宋
BaseFont
fsChinese
=
loadChineseFont
(
"
/fonts/
simfang.ttf"
);
BaseFont
fsChinese
=
loadChineseFont
(
"simfang.ttf"
);
// WINGDNG2
BaseFont
WINGDNG2
=
loadChineseFont
(
"
/fonts/
WINGDNG2.ttf"
);
BaseFont
WINGDNG2
=
loadChineseFont
(
"WINGDNG2.ttf"
);
// 添加水印
writer
.
setPageEvent
(
new
WatermarkPageEvent
(
watermark
,
fsChinese
));
...
...
@@ -116,23 +116,34 @@ public class ProjectInfoToPDF {
/**
* 加载中文字体
* @param font
Path 字体文件路径(相对于resources目录)
* @param font
Name 字体文件名
* @return BaseFont 中文字体
* @throws RuntimeException 加载字体失败时抛出异常
*/
private
static
BaseFont
loadChineseFont
(
String
font
Path
)
{
private
static
BaseFont
loadChineseFont
(
String
font
Name
)
{
try
{
// 从资源文件夹加载字体
String
path
=
ProjectInfoToPDF
.
class
.
getResource
(
fontPath
).
getPath
();
// 根据字体文件类型使用不同的加载方式
if
(
fontPath
.
toLowerCase
().
endsWith
(
".ttc"
))
{
return
BaseFont
.
createFont
(
path
+
",0"
,
BaseFont
.
WINANSI
,
BaseFont
.
EMBEDDED
);
if
(
"linux"
.
equals
(
getCurrentOperatingSystem
()))
{
if
(
fontName
.
toLowerCase
().
endsWith
(
".ttc"
))
return
BaseFont
.
createFont
(
"/usr/share/fonts/"
+
fontName
+
",0"
,
BaseFont
.
IDENTITY_H
,
BaseFont
.
EMBEDDED
);
else
return
BaseFont
.
createFont
(
"/usr/share/fonts/"
+
fontName
,
BaseFont
.
IDENTITY_H
,
BaseFont
.
EMBEDDED
);
}
else
{
return
BaseFont
.
createFont
(
path
,
BaseFont
.
WINANSI
,
BaseFont
.
EMBEDDED
);
if
(
fontName
.
toLowerCase
().
endsWith
(
".ttc"
))
return
BaseFont
.
createFont
(
"c:/Windows/Fonts/"
+
fontName
+
",0"
,
BaseFont
.
IDENTITY_H
,
BaseFont
.
NOT_EMBEDDED
);
else
return
BaseFont
.
createFont
(
"c:/Windows/Fonts/"
+
fontName
,
BaseFont
.
IDENTITY_H
,
BaseFont
.
NOT_EMBEDDED
);
}
// // 从资源文件夹加载字体
// String path = ProjectInfoToPDF.class.getResource(fontPath).getPath();
//
// // 根据字体文件类型使用不同的加载方式
// if (fontPath.toLowerCase().endsWith(".ttc")) {
// return BaseFont.createFont(path + ",0", BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
// } else {
// return BaseFont.createFont(path, BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
// }
}
catch
(
Exception
e
)
{
throw
new
RuntimeException
(
"加载字体文件失败,请确保
resources目录下存在字体文件 "
+
fontPath
+
":"
+
e
.
getMessage
(),
e
);
throw
new
RuntimeException
(
"加载字体文件失败,请确保
系统中存在字体文件 "
+
fontName
+
":"
+
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