From 03f3d70b6770a889c3918d41951c27dfa08a21bf Mon Sep 17 00:00:00 2001 From: linzhijie <19970921lzj> Date: 星期三, 04 八月 2021 17:59:51 +0800 Subject: [PATCH] PAQ 改为python转换pdf --- src/main/java/com/ots/project/tool/ShellTool.java | 49 ++++++++++++++++++++++--------------------------- 1 files changed, 22 insertions(+), 27 deletions(-) diff --git a/src/main/java/com/ots/project/tool/ShellTool.java b/src/main/java/com/ots/project/tool/ShellTool.java index 715583b..5f65299 100644 --- a/src/main/java/com/ots/project/tool/ShellTool.java +++ b/src/main/java/com/ots/project/tool/ShellTool.java @@ -15,8 +15,7 @@ } else { builder.append("libreoffice6.4 --headless --convert-to "); } - - builder.append(type).append(" "); + builder.append(type).append(":impress_pdf_Export "); builder.append("--outdir " + targetPath).append(" "); builder.append(sourcePath).append(" "); @@ -27,34 +26,29 @@ } } catch (Exception e) { } - return run_cmd(builder.toString()); + return exec(builder.toString()); } - public static String run_cmd(String strcmd) { - // - Runtime rt = Runtime.getRuntime(); //Runtime.getRuntime()杩斿洖褰撳墠搴旂敤绋嬪簭鐨凴untime瀵硅薄 - Process ps = null; //Process鍙互鎺у埗璇ュ瓙杩涚▼鐨勬墽琛屾垨鑾峰彇璇ュ瓙杩涚▼鐨勪俊鎭�� + 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 { - ps = rt.exec(strcmd); //璇ュ璞$殑exec()鏂规硶鎸囩ずJava铏氭嫙鏈哄垱寤轰竴涓瓙杩涚▼鎵ц鎸囧畾鐨勫彲鎵ц绋嬪簭锛屽苟杩斿洖涓庤瀛愯繘绋嬪搴旂殑Process瀵硅薄瀹炰緥銆� - ps.waitFor(); //绛夊緟瀛愯繘绋嬪畬鎴愬啀寰�涓嬫墽琛屻�� - } catch (IOException e1) { - e1.printStackTrace(); - } catch (InterruptedException e) { - // TODO Auto-generated catch block - e.printStackTrace(); + File file = new File(sourcePath.replaceAll(".docx", ".pdf")); + if (file.exists()) { + file.delete(); + } + } catch (Exception e) { } - - int i = ps.exitValue(); //鎺ユ敹鎵ц瀹屾瘯鐨勮繑鍥炲�� - if (i == 0) { - System.out.println("鎵ц瀹屾垚."); - } else { - System.out.println("鎵ц澶辫触."); - } - - ps.destroy(); //閿�姣佸瓙杩涚▼ - ps = null; - - return null; + return exec(builder.toString()); } private static String exec(String command) { @@ -80,6 +74,7 @@ return returnString; } public static void main(String[] args) { - System.out.println(exec("libreoffice6.4 --headless --convert-to /root/灏忕孩.docx 灏忕孩.pdf ")); + //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")); } } -- Gitblit v1.9.1