| | |
| | | */ |
| | | public static boolean word2PDF(String inputFile, String pdfFile) { |
| | | ComThread.InitMTA(true); |
| | | long start = System.currentTimeMillis(); |
| | | //long start = System.currentTimeMillis(); |
| | | ActiveXComponent app = null; |
| | | Dispatch doc = null; |
| | | try { |
| | |
| | | // word保存为pdf格式宏,值为17 |
| | | Dispatch.call(doc, "SaveAs", pdfFile, wdFormatPDF);// word保存为pdf格式宏,值为17 |
| | | |
| | | long end = System.currentTimeMillis(); |
| | | //long end = System.currentTimeMillis(); |
| | | |
| | | System.out.println("用时:" + (end - start) + "ms."); |
| | | //System.out.println("用时:" + (end - start) + "ms."); |
| | | return true; |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | System.out.println("========Error:文档转换失败:" + e.getMessage()); |
| | | throw e; |
| | | |
| | | } finally { |
| | | Dispatch.call(doc, "Close", false); |
| | | System.out.println("关闭文档"); |
| | | if (app != null) |
| | | app.invoke("Quit", new Variant[] {}); |
| | | if (app != null) { |
| | | app.invoke("Quit", new Variant[]{}); |
| | | } |
| | | // 如果没有这句话,winword.exe进程将不会关闭 |
| | | ComThread.Release(); |
| | | ComThread.quitMainSTA(); |
| | | } |
| | | return false; |
| | | |
| | | } |
| | | |
| | | public static void main(String[] arg){ |