| | |
| | | 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.util.ArrayList; |
| | | import java.util.Arrays; |
| | |
| | | } |
| | | |
| | | /** |
| | | * 执行python脚本 docx转pdf |
| | | * @param filePath |
| | | */ |
| | | public static void convertPythonPDF(String pythonScript,String filePath){ |
| | | try { |
| | | File file = new File(filePath); |
| | | if(!file.exists()){ |
| | | file.mkdirs(); |
| | | } |
| | | //手动替换输出pdf名称 |
| | | String output = filePath.replaceAll(".docx", ".pdf"); |
| | | String[] args1 = new String[] { "python3", pythonScript, filePath, output }; |
| | | // 执行py文件 |
| | | Process proc = Runtime.getRuntime().exec(args1); |
| | | BufferedReader in = new BufferedReader(new InputStreamReader(proc.getInputStream(), "GBK")); |
| | | String line = null; |
| | | log.info("python执行命令:{}", Arrays.toString(args1)); |
| | | log.info("python执行返回"); |
| | | while ((line = in.readLine()) != null) { |
| | | log.info(line); |
| | | } |
| | | in.close(); |
| | | proc.waitFor(); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * aspose-words:jdk17:23.4 版本 |
| | | */ |
| | | public static void registerWord() throws Exception { |