Browse Source

目录字体

aQiu 3 months ago
parent
commit
e923efd6f0
1 changed files with 7 additions and 0 deletions
  1. 7 0
      src/main/java/org/example/mybatisplus/tools/WordToPdfUtil.java

+ 7 - 0
src/main/java/org/example/mybatisplus/tools/WordToPdfUtil.java

@@ -44,6 +44,13 @@ public class WordToPdfUtil {
             // 创建一个Document对象,指定要转换的Word文档路径。
             //要转换的word文件
             Document doc = new Document(wordPath);
+            // 获取目录样式,例如 "TOC 1"
+            Style tocStyle = doc.getStyles().getByStyleIdentifier(StyleIdentifier.TOC_1);
+
+            // 设置字体加粗
+            tocStyle.getFont().setBold(true);
+            tocStyle.getFont().setSize(12); // 可以设置其他字体属性,如大小
+
             doc.updateFields();//更新目录
             doc.save(wordPath, SaveFormat.DOCX);
             // 将Word文档保存为PDF格式,写入到之前创建的PDF文件中。