@Test public void word2pdf() throws Exception { String inputFile = "D:\\t\\补充协议FJ07A04.docx"; String pdfFile = "D:\\t\\补充协议FJ07A04.pdf"; JacobUtils.word2PDF(inputFile, pdfFile); }
public static void word2PDF(String inputFile, String pdfFile) { ActiveXComponent app = new ActiveXComponent("Word.Application"); app.setProperty("Visible", false); Dispatch docs = app.getProperty("Documents").toDispatch(); Dispatch doc = Dispatch.call(docs, "Open", inputFile, false, true ).toDispatch(); Dispatch.call(doc, "ExportAsFixedFormat", pdfFile, wdFormatPDF); Dispatch.call(doc, "Close", false); app.invoke("Quit", 0); }
JacobUtils { public static void word2PDF(String inputFile, String pdfFile) { ActiveXComponent app = new ActiveXComponent("Word.Application"); app.setProperty("Visible", false); Dispatch docs = app.getProperty("Documents").toDispatch(); Dispatch doc = Dispatch.call(docs, "Open", inputFile, false, true ).toDispatch(); Dispatch.call(doc, "ExportAsFixedFormat", pdfFile, wdFormatPDF); Dispatch.call(doc, "Close", false); app.invoke("Quit", 0); } }
JacobUtils { public static void word2PDF(String inputFile, String pdfFile) { ActiveXComponent app = new ActiveXComponent("Word.Application"); app.setProperty("Visible", false); Dispatch docs = app.getProperty("Documents").toDispatch(); Dispatch doc = Dispatch.call(docs, "Open", inputFile, false, true ).toDispatch(); Dispatch.call(doc, "ExportAsFixedFormat", pdfFile, wdFormatPDF); Dispatch.call(doc, "Close", false); app.invoke("Quit", 0); }  }
JacobUtils { public static void word2PDF(String inputFile, String pdfFile) { ActiveXComponent app = new ActiveXComponent("Word.Application"); app.setProperty("Visible", false); Dispatch docs = app.getProperty("Documents").toDispatch(); Dispatch doc = Dispatch.call(docs, "Open", inputFile, false, true ).toDispatch(); Dispatch.call(doc, "ExportAsFixedFormat", pdfFile, wdFormatPDF); Dispatch.call(doc, "Close", false); app.invoke("Quit", 0); }  void convert2PDF(String inputFile, String pdfFile); void convert2PDF(String inputFile); static void word2PDF(String inputFile, String pdfFile); static void excel2PDF(String inputFile, String pdfFile); static void ppt2PDF(String inputFile, String pdfFile); }
JacobUtils { public static void word2PDF(String inputFile, String pdfFile) { ActiveXComponent app = new ActiveXComponent("Word.Application"); app.setProperty("Visible", false); Dispatch docs = app.getProperty("Documents").toDispatch(); Dispatch doc = Dispatch.call(docs, "Open", inputFile, false, true ).toDispatch(); Dispatch.call(doc, "ExportAsFixedFormat", pdfFile, wdFormatPDF); Dispatch.call(doc, "Close", false); app.invoke("Quit", 0); }  void convert2PDF(String inputFile, String pdfFile); void convert2PDF(String inputFile); static void word2PDF(String inputFile, String pdfFile); static void excel2PDF(String inputFile, String pdfFile); static void ppt2PDF(String inputFile, String pdfFile);  }