Commit 1ed870f0 by zhangxingmin

push

parent 6021871e
......@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment