[测评系统]--测评系统核心代码库
linzhijie
2021-08-06 17ac23e93792f1403297dfa783c85db0c10abb20
PAQ 模板支持
1个文件已添加
2个文件已修改
61 ■■■■■ 已修改文件
src/main/java/com/ots/common/utils/poi/WordUtil.java 3 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/ots/project/tool/PdfUtil.java 35 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/ots/project/tool/ShellTool.java 23 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/ots/common/utils/poi/WordUtil.java
@@ -9,6 +9,7 @@
import com.ots.project.exam.domain.TReportTemplate;
import com.ots.project.exam.dto.JAQTableStyle;
import com.ots.project.exam.dto.WordParam;
import com.ots.project.tool.PdfUtil;
import com.ots.project.tool.ShellTool;
import com.ots.project.tool.exam.ExamUtil;
import com.ots.project.tool.exam.ImageUtil;
@@ -771,7 +772,7 @@
            if(!ReportTypeEnum.PAQ.getCode().equals(reportType)){
                ShellTool.execLibreofficeCommand("pdf", EssConfig.getProfile() + "/" + reportName, EssConfig.getProfile() + "/");
            }else{
                ShellTool.execPythonCommand(1,EssConfig.getProfile() + "/" + reportName);
                PdfUtil.convertPDF(EssConfig.getProfile() + "/" + reportName);
            }
            zipFilePath = getPdfPath(reportName);
            
src/main/java/com/ots/project/tool/PdfUtil.java
New file
@@ -0,0 +1,35 @@
package com.ots.project.tool;
import com.aspose.words.Document;
import com.aspose.words.SaveFormat;
import lombok.extern.slf4j.Slf4j;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
@Slf4j
public class PdfUtil {
    public static void convertPDF(String input){
        try {
            //手动替换输出pdf名称
            String output = input.replaceAll(".docx", ".pdf");
            long old = System.currentTimeMillis();
            FileInputStream fileInput = new FileInputStream(input);
            Document pres = new Document(fileInput);
            FileOutputStream out = new FileOutputStream(new File(output));
            pres.save(out, SaveFormat.PDF);
            out.close();
            long now = System.currentTimeMillis();
            log.info("doc转pdf耗时:{}秒", ((now - old) / 1000.0));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    public static void main(String[] args) {
        convertPDF("D:\\测评系统\\home\\林_PAQ_IA_CN.docx");
    }
}
src/main/java/com/ots/project/tool/ShellTool.java
@@ -29,28 +29,6 @@
        return exec(builder.toString());
    }
    public static String execPythonCommand(Integer type,String sourcePath) {
        String os = System.getProperty("os.name");
        StringBuilder builder = new StringBuilder();
        if(type == 0){
            //服务器
            builder.append("python /bin/doc2pdf.py ");
        }else{
            //本地测试
            builder.append("python D:\\Project\\yaohuo\\doc2pdf.py ");
        }
        builder.append(sourcePath).append(" ");
        try {
            File file = new File(sourcePath.replaceAll(".docx", ".pdf"));
            if (file.exists()) {
                file.delete();
            }
        } catch (Exception e) {
        }
        return exec(builder.toString());
    }
    private static String exec(String command) {
        String returnString = "";
        Runtime runTime = Runtime.getRuntime();
@@ -75,6 +53,5 @@
    }
    public static void main(String[] args) {
        //System.out.println(exec("soffice.exe --headless --invisible --convert-to  D:/ots/uploadPath/upload/2021/02/28/01e01cf7e372ba8b1c5d24b8d69a46f8.docx 01e01cf7e372ba8b1c5d24b8d69a46f8.pdf "));
        System.out.println(execPythonCommand(1,"D:\\测评系统\\home\\林_PAQ_IA_CN.docx"));
    }
}