Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yd-csf
Overview
Overview
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
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
xingmin
yd-csf
Commits
9975dcd1
Commit
9975dcd1
authored
Nov 21, 2025
by
jianan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
新单跟进73
parent
506522ed
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
20 deletions
+11
-20
yd-csf-service/src/main/java/com/yd/csf/service/service/PolicyReportPdfService.java
+11
-20
No files found.
yd-csf-service/src/main/java/com/yd/csf/service/service/PolicyReportPdfService.java
View file @
9975dcd1
...
...
@@ -12,11 +12,13 @@ import com.lowagie.text.pdf.PdfWriter;
import
com.yd.common.exception.BusinessException
;
import
com.yd.csf.service.dto.PolicyReportData
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.io.IOUtils
;
import
org.springframework.stereotype.Service
;
import
java.awt.*
;
import
java.io.ByteArrayOutputStream
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.math.BigDecimal
;
@Service
...
...
@@ -356,27 +358,16 @@ public class PolicyReportPdfService {
try
{
BaseFont
baseFont
=
null
;
// 方法1: 使用绝对路径
String
absolutePath
=
"D:\\IdeaProjects\\yd-csf\\yd-csf-service\\src\\main\\resources\\font\\DFKai-SB.ttf"
;
// 方法2: 使用classpath相对路径(如果字体文件在resources目录下)
String
resourcePath
=
"font/DFKai-SB.ttf"
;
java
.
io
.
File
fontFile
=
new
java
.
io
.
File
(
absolutePath
);
if
(
fontFile
.
exists
())
{
try
{
baseFont
=
BaseFont
.
createFont
(
absolutePath
,
BaseFont
.
IDENTITY_H
,
BaseFont
.
EMBEDDED
);
log
.
info
(
"成功从绝对路径加载繁体楷体: {}"
,
absolutePath
);
}
catch
(
Exception
e
)
{
log
.
warn
(
"绝对路径加载失败,尝试classpath路径"
);
// 尝试从classpath加载
try
{
baseFont
=
BaseFont
.
createFont
(
resourcePath
,
BaseFont
.
IDENTITY_H
,
BaseFont
.
EMBEDDED
);
log
.
info
(
"成功从classpath加载繁体楷体: {}"
,
resourcePath
);
}
catch
(
IOException
ioException
)
{
log
.
error
(
"classpath路径加载失败,使用备用字体"
,
ioException
);
}
// 优先使用Classpath资源流加载
try
{
InputStream
fontStream
=
getClass
().
getClassLoader
().
getResourceAsStream
(
"font/DFKai-SB.ttf"
);
if
(
fontStream
!=
null
)
{
byte
[]
fontData
=
IOUtils
.
toByteArray
(
fontStream
);
baseFont
=
BaseFont
.
createFont
(
"DFKai-SB.ttf"
,
BaseFont
.
IDENTITY_H
,
BaseFont
.
EMBEDDED
,
BaseFont
.
CACHED
,
fontData
,
null
);
log
.
info
(
"成功从字节数组加载繁体楷体"
);
}
}
catch
(
Exception
e
)
{
log
.
warn
(
"Classpath加载失败: {}"
,
e
.
getMessage
());
}
// 如果还是失败,使用备用字体
...
...
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