使用 Java 取得與更新簡報資訊
概觀
本文說明如何在 Aspose.Slides 中檢查簡報資訊。它說明如何在不載入整個檔案的情況下判斷簡報的目前格式、讀取其文件屬性,並在需要時更新這些屬性。
範例是基於 PresentationInfo 與 DocumentProperties API,示範處理簡報中介資料的典型操作。
檢查簡報格式
在處理簡報之前,您可能想先了解該簡報目前的格式(PPT、PPTX、ODP 等)。
您可以在不載入簡報的情況下檢查其格式。請參考以下 Java 程式碼:
IPresentationInfo info = PresentationFactory.getInstance().getPresentationInfo("pres.pptx");
System.out.println(info.getLoadFormat()); // PPTX
IPresentationInfo info2 = PresentationFactory.getInstance().getPresentationInfo("pres.ppt");
System.out.println(info2.getLoadFormat()); // PPT
IPresentationInfo info3 = PresentationFactory.getInstance().getPresentationInfo("pres.odp");
System.out.println(info3.getLoadFormat()); // ODP
取得簡報屬性
以下 Java 程式碼示範如何取得簡報屬性(簡報的相關資訊):
IPresentationInfo info = PresentationFactory.getInstance().getPresentationInfo("pres.pptx");
IDocumentProperties props = info.readDocumentProperties();
System.out.println(props.getCreatedTime());
System.out.println(props.getSubject());
System.out.println(props.getTitle());
// ..
您可能想查看 DocumentProperties 類別下的屬性。
更新簡報屬性
Aspose.Slides 提供了 PresentationInfo.updateDocumentProperties 方法,可讓您變更簡報屬性。
假設我們有一個 PowerPoint 簡報,其文件屬性如下所示。

以下程式碼示範如何編輯部分簡報屬性:
String fileName = "sample.pptx";
IPresentationInfo info = PresentationFactory.getInstance().getPresentationInfo(fileName);
IDocumentProperties properties = info.readDocumentProperties();
properties.setTitle("My title");
properties.setLastSavedTime(new Date());
info.updateDocumentProperties(properties);
info.writeBindedPresentation(fileName);
變更文件屬性的結果如下所示。

實用連結
若需取得有關簡報及其安全屬性的更多資訊,以下連結可能對您有幫助:
常見問題
如何檢查字型是否已嵌入以及哪些字型已嵌入?
請在簡報層級查找 embedded-font information,然後將這些條目與 fonts actually used across content 的字型集合進行比較,以辨識哪些字型對於呈現至關重要。
如何快速判斷檔案中是否有隱藏投影片以及有多少張?
遍歷 slide collection,檢查每張投影片的 visibility flag。
我可以偵測是否使用自訂投影片大小與方向,且是否與預設值不同嗎?
可以。將目前的 slide size 與方向與標準預設值比較;此作法有助於預測列印與匯出的行為。
是否有快速方式檢查圖表是否引用外部資料來源?
可以。遍歷所有 charts,檢查其 data source,並註明資料是內部還是基於連結,包括任何失效的連結。
如何評估可能降低渲染或 PDF 匯出速度的「大型」投影片?
對每張投影片,統計物件數量並查找大型圖片、透明度、陰影、動畫與多媒體;根據這些因素給予大致的複雜度分數,以標記潛在的效能熱點。