[测评系统]--测评系统核心代码库
wzp
2024-12-30 6620dc7b245127616cb580700eb026da03e96de5
src/main/java/com/ots/project/tool/PdfUtil.java
@@ -3,10 +3,9 @@
import com.aspose.words.*;
import lombok.extern.slf4j.Slf4j;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.*;
import java.lang.reflect.Constructor;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@@ -18,7 +17,7 @@
     * 设置用户字体位置
     */
    public static void setFont() {
        String[] fonts = {"C:\\Users\\大头\\AppData\\Local\\Microsoft\\Windows\\Fonts\\", "C:\\Users\\datou\\AppData\\Local\\Microsoft\\Windows\\Fonts\\", "/usr/share/fonts"};
        String[] fonts = {"C:\\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);
@@ -42,7 +41,32 @@
            pres.save(out, SaveFormat.PDF);
            out.close();
            long now = System.currentTimeMillis();
            log.info("doc转pdf耗时:{}秒", ((now - old) / 1000.0));
            log.info("【转换】doc转pdf耗时:{}秒", ((now - old) / 1000.0));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    /**
     * docker word转pdf
     * @param profile
     * @param docx2pdfPath
     * @param fileName
     */
    public static void dockerConvertPDF(String profile,String docx2pdfPath,String fileName){
        try {
            String command = MessageFormat.format(docx2pdfPath,profile,fileName);
            // 执行docker 命令
            Process proc = Runtime.getRuntime().exec(command);
            BufferedReader in = new BufferedReader(new InputStreamReader(proc.getInputStream(), "GBK"));
            String line = null;
            log.info("docker执行命令:{}", command);
            log.info("docker执行返回");
            while ((line = in.readLine()) != null) {
                log.info(line);
            }
            in.close();
            proc.waitFor();
        } catch (Exception e) {
            e.printStackTrace();
        }
@@ -82,7 +106,7 @@
    public static void main(String[] args) {
        //convertPDF("D:\\测评系统\\home\\林_PAQ_GS_TH.docx");
        convertPDF("C:\\Users\\大头\\Desktop\\林3_CIAQ_IA_CN.docx");
        convertPDF("C:\\Users\\mac\\Desktop\\API_Fan_IA_CN.docx");
    }
}