用word2010,
文档时doc格式,打开时报:
Word转PDF出错:Invoke of: Open
Source: Microsoft Word
(C:...\tmp_863d2debe0f96a8ce2a28f63c5...) 。为帮助保护您的计算机,不能打开此文件。
public static boolean word2pdf(String source, String target) { System.out.println("Word转PDF开始启动..."); long start = System.currentTimeMillis(); ActiveXComponent app = null; try { app = new ActiveXComponent("Word.Application"); app.setProperty("Visible", false); Dispatch docs = app.getProperty("Documents").toDispatch(); System.out.println("打开文档:" + source); Dispatch doc = Dispatch.call(docs, "Open", source, false, true).toDispatch(); System.out.println("转换文档到PDF:" + target); File tofile = new File(target); if (tofile.exists()) { tofile.delete(); } Dispatch.call(doc, "SaveAs", target, wdFormatPDF); Dispatch.call(doc, "Close", false); long end = System.currentTimeMillis(); System.out.println("转换完成,用时:" + (end - start) + "ms"); return true; } catch (Exception e) { System.out.println("Word转PDF出错:" + e.getMessage()); return false; } finally { if (app != null) { app.invoke("Quit", wdDoNotSaveChanges); } } }
不知道怎么解决,请教
开满天机
相关分类