| | |
| | | |
| | | import java.io.*; |
| | | import java.lang.reflect.Constructor; |
| | | import java.text.MessageFormat; |
| | | import java.util.ArrayList; |
| | | import java.util.Arrays; |
| | | import java.util.List; |
| | |
| | | * 设置用户字体位置 |
| | | */ |
| | | 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); |
| | |
| | | } |
| | | |
| | | /** |
| | | * 执行python脚本 docx转pdf |
| | | * @param filePath |
| | | * docker word转pdf |
| | | * @param profile |
| | | * @param docx2pdfPath |
| | | * @param fileName |
| | | */ |
| | | public static void convertPythonPDF(String pythonScript,String filePath){ |
| | | public static void dockerConvertPDF(String profile,String docx2pdfPath,String fileName){ |
| | | 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); |
| | | 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("python执行命令:{}", Arrays.toString(args1)); |
| | | log.info("python执行返回"); |
| | | log.info("docker执行命令:{}", command); |
| | | log.info("docker执行返回"); |
| | | while ((line = in.readLine()) != null) { |
| | | log.info(line); |
| | | } |
| | |
| | | |
| | | 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"); |
| | | } |
| | | |
| | | } |