在 C++ 中從 PDF 或 HTML 匯入簡報

簡介

使用 Aspose.Slides for C++,您可以從其他格式的檔案匯入簡報。Aspose.Slides 提供 SlideCollection 類別,允許您從 PDF、HTML 文件等匯入簡報。

從 PDF 匯入 PowerPoint

在此情況下,您可以將 PDF 轉換為 PowerPoint 簡報。

pdf-to-powerpoint

  1. 建立 Presentation 類別的物件。
  2. 呼叫 AddFromPdf() 方法並傳入 PDF 檔案。
  3. 使用 Save() 方法將檔案儲存為 PowerPoint 格式。

以下 C++ 程式碼示範了 PDF 轉換為 PowerPoint 的操作:

auto pres = System::MakeObject<Presentation>();
    
pres->get_Slides()->AddFromPdf(u"InputPDF.pdf");
pres->Save(u"OutputPresentation.pptx", SaveFormat::Pptx);

從 HTML 匯入 PowerPoint

在此情況下,您可以將 HTML 文件轉換為 PowerPoint 簡報。

  1. 建立 Presentation 類別的執行個體。
  2. 呼叫 AddFromHtml() 方法並傳入 HTML 檔案。
  3. 使用 Save() 方法將檔案儲存為 PowerPoint 格式。

以下 C++ 程式碼示範了 HTML 轉換為 PowerPoint 的操作:

auto presentation = System::MakeObject<Presentation>();

{
    auto htmlStream = System::IO::File::OpenRead(u"page.html");
    presentation->get_Slides()->AddFromHtml(htmlStream);
}

presentation->Save(u"MyPresentation.pptx", SaveFormat::Pptx);

常見問題

匯入 PDF 時表格是否會被保留,且其偵測能否改進?

匯入過程中可以偵測表格;PdfImportOptions 包含 set_DetectTables 方法,可啟用表格辨識。其效能取決於 PDF 的結構。