取得與更新 Android 上的簡報資訊
概觀
本文說明如何在 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);
變更文件屬性的結果如下所示。

實用連結
若需取得有關簡報及其安全屬性的更多資訊,以下連結可能對您有幫助:
- Checking whether a Presentation is Encrypted
- Checking whether a Presentation is Write Protected (read-only)
- Checking whether a Presentation is Password Protected Before Loading it
- Confirming the Password Used to Protect a Presentation
常見問題
如何檢查字型是否已嵌入,以及哪些字型被嵌入?
請在簡報層級查找 embedded-font information,再將這些條目與 實際使用的字型 集合比較,以辨識哪些字型對呈現至關重要。
如何快速判斷檔案是否包含隱藏投影片以及數量?
遍歷 slide collection,檢查每張投影片的 visibility flag。
能否偵測是否使用自訂投影片大小與方向,且是否與預設不同?
可以。將目前的 slide size 與方向與標準預設進行比較;此資訊有助於預測列印與匯出的行為。
是否有快速方式看圖表是否參考外部資料來源?
可以。遍歷所有 charts,檢查其 data source,並註明資料是內部還是基於連結,包括任何斷開的連結。
如何評估可能降低渲染或 PDF 匯出速度的「重量」投影片?
對每張投影片統計物件數量,並留意大型影像、透明度、陰影、動畫與多媒體;給予大致的複雜度分數,以標記潛在的效能熱點。