在 C++ 中擷取與更新簡報資訊

概觀

本文說明如何在 Aspose.Slides 中檢查簡報資訊。它解釋如何在不載入完整檔案的情況下判斷簡報的目前格式、讀取其文件屬性,並在需要時更新這些屬性。

這些範例基於 PresentationInfoDocumentProperties API,示範了處理簡報中繼資料的典型操作。

檢查簡報格式

在處理簡報之前,您可能想要了解該簡報目前使用的格式(PPT、PPTX、ODP 等)。

您可以在不載入簡報的情況下檢查其格式。請參考以下 C++ 程式碼:

auto info = PresentationFactory::get_Instance()->GetPresentationInfo(u"pres.pptx");
// PPTX
Console::WriteLine(ObjectExt::ToString(info->get_LoadFormat()));

auto info2 = PresentationFactory::get_Instance()->GetPresentationInfo(u"pres.ppt");
// PPT
Console::WriteLine(ObjectExt::ToString(info2->get_LoadFormat()));

auto info3 = PresentationFactory::get_Instance()->GetPresentationInfo(u"pres.odp");
// ODP
Console::WriteLine(ObjectExt::ToString(info3->get_LoadFormat()));

取得簡報屬性

以下 C++ 程式碼示範如何取得簡報屬性(有關簡報的資訊):

auto info = PresentationFactory::get_Instance()->GetPresentationInfo(u"pres.pptx");
auto props = info->ReadDocumentProperties();
Console::WriteLine(ObjectExt::ToString(props->get_CreatedTime()));
Console::WriteLine(props->get_Subject());
Console::WriteLine(props->get_Title());
// ..

更新簡報屬性

Aspose.Slides 提供 PresentationInfo::UpdateDocumentProperties 方法,允許您變更簡報屬性。

假設我們有一個 PowerPoint 簡報,其文件屬性如下所示。

PowerPoint 簡報的原始文件屬性

以下程式碼示範如何編輯某些簡報屬性:

auto fileName = u"sample.pptx";

auto info = PresentationFactory::get_Instance()->GetPresentationInfo(fileName);

auto properties = info->ReadDocumentProperties();
properties->set_Title(u"My title");
properties->set_LastSavedTime(DateTime::get_Now());

info->UpdateDocumentProperties(properties);
info->WriteBindedPresentation(fileName);

變更文件屬性的結果如下所示。

PowerPoint 簡報的變更後文件屬性

實用連結

若要取得有關簡報及其安全屬性的更多資訊,以下連結可能對您有幫助:

常見問題

我該如何檢查字型是否已嵌入以及是哪一些字型?

在簡報層級查找 embedded-font information,然後將這些條目與 fonts actually used across content 的集合進行比對,即可辨識哪些字型對於呈現是關鍵的。

我該如何快速判斷檔案是否有隱藏投影片以及數量?

遍歷 slide collection 並檢查每張投影片的 visibility flag

我能偵測是否使用了自訂投影片大小與方向,且是否與預設不同嗎?

可以。將目前的 slide size and orientation 與標準預設值比較;這有助於預測列印與匯出的行為。

有沒有快速方法查看圖表是否引用外部資料來源?

可以。遍歷所有 charts,檢查其 data source,並註明資料是內部還是基於連結,亦包括任何斷開的連結。

我該如何評估可能導致渲染或 PDF 匯出緩慢的「沉重」投影片?

對每張投影片,統計物件數量並檢查是否有大型影像、透明度、陰影、動畫與多媒體;依此給予大致的複雜度分數,以標示可能的效能瓶頸。