本地电脑需要安装WPS介意的不需要往下看了,因为原装的jacob好像转有点问题最新的要jdk1.8以上so只能用wps插件了
资源下载地址:https://download.csdn.net/download/s1040342522/10549518
private static final Integer PPT_TO_PDF_OPERAND = 32;
public static void ppt2pdf(String srcFilePath, String pdfFilePath) throws Exception {
ActiveXComponent app = null;
Dispatch ppt = null;
try {
ComThread.InitSTA();
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
// Dispatch.callN(ppt, "SaveAs", new Variant(pdfFilePath));
} catch (Exception e) {
e.printStackTrace();
throw e;
} finally {
if (ppt != null) {
Dispatch.call(ppt, "Close");
}
if (app != null) {
app.invoke("Quit");
}
ComThread.Release();
}
}
public static void main(String[] args) throws Exception {
String path = "D://";
ppt2pdf(path + "2.pptx", path + "2x.pdf");
}