public void pptToPdf(String srcFilePath, String pdfFilePath) throws Exception {
ActiveXComponent app = null;
Dispatch ppt = null;
try {
ComThread.InitSTA();
// app = new ActiveXComponent("PowerPoint.Application");
//改成 kwpp
app = new ActiveXComponent("KWPP.Application");
Dispatch ppts = app.getProperty("Presentations").toDispatch();
/*
* call
* param 4: ReadOnly
* param 5: Untitled指定文件是否有标题
* param 6: WithWindow指定文件是否可见
* */
ppt = Dispatch.call(ppts, "Open", srcFilePath, true, true, false).toDispatch();
Dispatch.call(ppt, "SaveAs", pdfFilePath, PPT_TO_PDF_OPERAND); // ppSaveAsPDF为特定值32
} catch (Exception e) {
e.printStackTrace();
throw e;
} finally {
if (ppt != null) {
Dispatch.call(ppt, "Close");
}
if (app != null) {
app.invoke("Quit");
}
ComThread.Release();
}
}