From 99f7f9adac08f3a3fa3211f7a6062c26d62fa224 Mon Sep 17 00:00:00 2001
From: 林致杰 <1003392067@qq.com>
Date: 星期日, 26 六月 2022 18:35:15 +0800
Subject: [PATCH] 组别报告解析生成

---
 src/main/java/com/ots/project/tool/PdfUtil.java |   27 +++++++++++++++++++++++----
 1 files changed, 23 insertions(+), 4 deletions(-)

diff --git a/src/main/java/com/ots/project/tool/PdfUtil.java b/src/main/java/com/ots/project/tool/PdfUtil.java
index ff31931..5bd4622 100644
--- a/src/main/java/com/ots/project/tool/PdfUtil.java
+++ b/src/main/java/com/ots/project/tool/PdfUtil.java
@@ -1,23 +1,41 @@
 package com.ots.project.tool;
 
-import com.aspose.words.Document;
-import com.aspose.words.SaveFormat;
+import com.aspose.words.*;
 import lombok.extern.slf4j.Slf4j;
 
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileOutputStream;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
 
 @Slf4j
 public class PdfUtil {
 
+    /**
+     * 璁剧疆鐢ㄦ埛瀛椾綋浣嶇疆
+     */
+    public static void setFont(){
+        String[] fonts = {"C:\\Users\\澶уご\\AppData\\Local\\Microsoft\\Windows\\Fonts\\","C:\\Users\\datou\\AppData\\Local\\Microsoft\\Windows\\Fonts\\","/usr/share/fonts"};
+        List<FontSourceBase> fontSources = new ArrayList(Arrays.asList(FontSettings.getDefaultInstance().getFontsSources()));
+        for (int i = 0; i < fonts.length; i++) {
+            FolderFontSource folderFontSource = new FolderFontSource(fonts[i],true);
+            fontSources.add(folderFontSource);
+        }
+        FontSourceBase[] fontSourceBases = fontSources.toArray(new FontSourceBase[fontSources.size()]);
+        FontSettings.getDefaultInstance().setFontsSources(fontSourceBases);
+    }
+
     public static void convertPDF(String input){
         try {
+            setFont();
+            Document pres = null;
             //鎵嬪姩鏇挎崲杈撳嚭pdf鍚嶇О
             String output = input.replaceAll(".docx", ".pdf");
             long old = System.currentTimeMillis();
             FileInputStream fileInput = new FileInputStream(input);
-            Document pres = new Document(fileInput);
+            pres = new Document(fileInput);
             FileOutputStream out = new FileOutputStream(new File(output));
             pres.save(out, SaveFormat.PDF);
             out.close();
@@ -29,7 +47,8 @@
     }
 
     public static void main(String[] args) {
-        convertPDF("D:\\娴嬭瘎绯荤粺\\home\\鏋梍PAQ_IA_CN.docx");
+        //convertPDF("D:\\娴嬭瘎绯荤粺\\home\\鏋梍PAQ_GS_TH.docx");
+        convertPDF("C:\\Users\\澶уご\\Desktop\\MAQ缁勫埆鎶ュ憡\\娴嬭瘯_MAQTR_IA_EN.docx");
     }
 
 }

--
Gitblit v1.9.1