使用 Python 匯入簡報

簡介

使用 Aspose.Slides for Python via .NET,您可以從其他檔案格式匯入內容至簡報。SlideCollection 類別提供從 PDF、HTML 及其他來源匯入投影片的方法。

將 PDF 轉換為簡報

本節說明如何使用 Aspose.Slides 將 PDF 轉換為簡報。它將引導您匯入 PDF、將其頁面轉換為投影片,並將結果儲存為 PPTX 檔案。

pdf-to-powerpoint

  1. 建立 Presentation 類別的實例。
  2. 呼叫 add_from_pdf 方法並傳入 PDF 檔案。
  3. 使用 save 方法將簡報儲存為 PowerPoint 格式。

以下 Python 範例示範將 PDF 轉換為簡報:

import aspose.slides as slides

with slides.Presentation() as presentation:
    presentation.slides.remove_at(0)

    presentation.slides.add_from_pdf("sample.pdf")

    presentation.save("output.pptx", slides.export.SaveFormat.PPTX)

將 HTML 轉換為簡報

本節說明如何使用 Aspose.Slides 將 HTML 內容匯入簡報。它涵蓋載入 HTML、將其轉換為保留文字、圖像和基本格式的投影片,並將結果儲存為 PPTX 檔案。

  1. 建立 Presentation 類別的實例。
  2. 呼叫 add_from_html 方法並傳入 HTML 檔案。
  3. 使用 save 方法將簡報儲存為 PowerPoint 格式。

以下 Python 範例示範將 HTML 轉換為簡報:

import aspose.slides as slides

with slides.Presentation() as presentation:
    presentation.slides.remove_at(0)

    with open("page.html", "rb") as html_stream:
        presentation.slides.add_from_html(html_stream)

    presentation.save("output.pptx", slides.export.SaveFormat.PPTX)

常見問題

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

匯入過程中可偵測表格;PdfImportOptions 包含一個 detect_tables 參數,可啟用表格辨識。其有效性取決於 PDF 的結構。