Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yd-oss
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-oss
Commits
1ed870f0
Commit
1ed870f0
authored
Oct 19, 2025
by
zhangxingmin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
push
parent
6021871e
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
32 additions
and
0 deletions
+32
-0
yd-oss-service/src/main/java/com/yd/oss/service/service/impl/PdfServiceImpl.java
+32
-0
No files found.
yd-oss-service/src/main/java/com/yd/oss/service/service/impl/PdfServiceImpl.java
View file @
1ed870f0
...
...
@@ -101,6 +101,9 @@ public class PdfServiceImpl<T> implements PdfService<T> {
// 使用Apache POI处理Word文档
XWPFDocument
document
=
new
XWPFDocument
(
new
FileInputStream
(
wordFile
));
// 修复:确保中文字体正确处理
ensureChineseFontSupport
(
document
);
// 替换文档中的占位符
replacePlaceholders
(
document
,
replacements
);
...
...
@@ -124,6 +127,35 @@ public class PdfServiceImpl<T> implements PdfService<T> {
}
/**
* 确保中文字体支持
*/
private
void
ensureChineseFontSupport
(
XWPFDocument
document
)
{
// 设置文档默认字体为支持中文的字体
for
(
XWPFParagraph
paragraph
:
document
.
getParagraphs
())
{
for
(
XWPFRun
run
:
paragraph
.
getRuns
())
{
// 设置中文字体
run
.
setFontFamily
(
"Microsoft YaHei"
);
// 微软雅黑
// 或者使用其他支持中文的字体
// run.setFontFamily("SimSun"); // 宋体
// run.setFontFamily("SimHei"); // 黑体
}
}
// 处理表格中的字体
for
(
XWPFTable
table
:
document
.
getTables
())
{
for
(
XWPFTableRow
row
:
table
.
getRows
())
{
for
(
XWPFTableCell
cell
:
row
.
getTableCells
())
{
for
(
XWPFParagraph
paragraph
:
cell
.
getParagraphs
())
{
for
(
XWPFRun
run
:
paragraph
.
getRuns
())
{
run
.
setFontFamily
(
"Microsoft YaHei"
);
}
}
}
}
}
}
/**
* 使用PdfUtil将Word转换为PDF
* @param wordFile
* @param pdfFile
...
...
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