開發四年只會寫業務代碼,分布式高并發都不會還做程式員?->>>
private boolean ppt2PDF(String inputFile, String pdfFile) {
ComThread.InitSTA();
long start = System.currentTimeMillis();
ActiveXComponent app = null;
Dispatch ppt = null;
try {
app = new ActiveXComponent("PowerPoint.Application");// 創建一個PPT物件
//app.setProperty("Visible", new Variant(true)); // 不可見打開(PPT轉換不運行隱藏,所以這里要注釋掉)
//app.setProperty("AutomationSecurity", new Variant(3)); // 禁用宏
Dispatch ppts = app.getProperty("Presentations").toDispatch();// 獲取文擋屬性
System.out.println("打開檔案 >>> " + inputFile);
// 呼叫Documents物件中Open方法打開檔案,并回傳打開的檔案物件Document
ppt = Dispatch.call(ppts, "Open", inputFile,
true,// ReadOnly
true,// Untitled指定檔案是否有標題
false// WithWindow指定檔案是否可見
).toDispatch();
System.out.println("轉換檔案 [" + inputFile + "] >>> [" + pdfFile + "]");
Dispatch.call(ppt, "SaveCopyAs", pdfFile, ppFormatPDF);
//Dispatch.call(ppt, "ExportAsFixedFormat", pdfFile, ppFormatPDF);
long end = System.currentTimeMillis();
System.out.println("用時:" + (end - start) + "ms.");
return true;
} catch (Exception e) {
e.printStackTrace();
System.out.println("========Error:檔案轉換失敗:" + e.getMessage());
} finally {
Dispatch.call(ppt, "Close");
System.out.println("關閉檔案");
if (app != null)
app.invoke("Quit", new Variant[] {});
}
ComThread.Release();
ComThread.quitMainSTA();
return false;
}
就是網上到處流傳的這段代碼,PPT轉pdf就會報錯
com.jacob.com.ComFailException: Invoke of: SaveAs Source: Microsoft PowerPoint 2013 Description: Presentation.SaveAs : PowerPoint 無法將 ^0 保存到 ^1。
PPT轉jpg也是這樣的錯誤,但是word和excel就不會,求解啊,,,
或者有什么其它的windows下office轉pdf的方法么(⊙v⊙)?
跪謝。
uj5u.com熱心網友回復:
我也遇到這個問題了,大神解決了嗎轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/123755.html
標籤:其他技術討論專區
