在 Python 中將 PowerPoint PPT 轉為 TIFF

TIFF 是一種流行的格式,用於將 PowerPoint 演示文稿轉換為圖像格式。此轉換可用於生成 PPT 幻燈片的縮略圖。在本文中,您將學習如何使用 Python 將 PowerPoint PPT 或 PPTX 轉換為 TIFF。此外,您將學習如何使用不同的選項自定義 PPT 到 TIFF 的轉換。

Python PowerPoint PPT 到 TIFF 轉換器

Aspose.Slides for Python 將 PowerPoint 演示文稿高保真地轉換為各種流行的圖像和文檔格式。我們將使用此庫將我們的 PPT/PPTX 演示文稿轉換為 TIFF 格式。您可以使用以下命令從 PyPI 安裝庫。

> pip install aspose.slides

在 Python 中將 PowerPoint PPTX 轉換為 TIFF

PowerPoint PPT/PPTX 到 TIFF 的轉換可以使用 Aspose.Slides for Python 在幾行代碼中完成,如下所示。

  • 使用 Presentation 類加載 PowerPoint PPT/PPTX。
  • 使用 Presentation.save(string, SaveFormat.TIFF) 方法將演示文稿保存為 TIFF。

以下代碼示例演示如何在 Python 中將 PowerPoint PPTX 文件轉換為 TIFF。

import aspose.slides as slides

# 負載演示
presentation = slides.Presentation("presentation.pptx")

# 將 PPT 另存為 TIFF
presentation.save("ppt-to-tiff.tiff", slides.export.SaveFormat.TIFF)

使用 Python 中的隱藏幻燈片將 PPT 轉換為 TIFF

通常,PowerPoint 演示文稿包含隱藏的幻燈片,默認情況下這些幻燈片不包含在 PPT 到 TIFF 的轉換中。但是,您可以啟用隱藏幻燈片的呈現,如下所示。

  • 首先,使用 Presentation 類加載 PowerPoint PPT/PPTX。
  • 然後,創建 TiffOptions 類的實例。
  • 將 TiffOptions.showhiddenslides 屬性設置為 True。
  • 使用 Presentation.save(string, SaveFormat.TIFF, TiffOptions) 方法將演示文稿保存為 TIFF。

以下代碼示例顯示瞭如何在 PPT 到 TIFF 轉換中包含隱藏的幻燈片。

import aspose.slides as slides

# 負載演示
presentation = slides.Presentation("presentation.pptx")

# 實例化 TiffOptions 類
opts = slides.export.TiffOptions()

# 設置像素格式
opts.show_hidden_slides = True

# 將 PPT 另存為 TIFF
presentation.save("ppt-to-tiff-hidden-slides.tiff", slides.export.SaveFormat.TIFF, opts)

PPT 到 TIFF - 自定義壓縮和圖像大小

您還可以在轉換過程中自定義生成的 TIFF 圖像的大小。此外,您可以更改轉換後的 TIFF 圖像的默認壓縮類型。以下步驟顯示如何在 PowerPoint PPT 到 TIFF 轉換中設置壓縮類型和圖像大小。

  • 首先,使用 Presentation 類加載 PowerPoint PPT/PPTX。
  • 然後,創建 TiffOptions 類的實例。
  • 使用 TiffOptions.imagesize 屬性設置圖像尺寸。
  • 使用 TiffOptions.compressiontype 屬性設置壓縮類型。
  • 使用 Presentation.save(string, SaveFormat.TIFF, TiffOptions) 方法將 PPT 轉換為 TIFF。

以下代碼示例顯示瞭如何使用自定義圖像大小和壓縮將 PPTX 轉換為 TIFF。

import aspose.slides as slides
import aspose.pydrawing as drawing

# 負載演示
presentation = slides.Presentation("presentation.pptx")

# 實例化 TiffOptions 類
opts = slides.export.TiffOptions()

# 設置壓縮類型
opts.compression_type = slides.export.TiffCompressionTypes.DEFAULT
opts.notes_comments_layouting.notes_position = slides.export.NotesPositions.BOTTOM_FULL

# 設置圖像 DPI
opts.dpi_x = 200
opts.dpi_y = 100

# 設置圖片大小
opts.image_size = drawing.Size(1728, 1078)

# 將 PPT 另存為 TIFF
presentation.save("ppt-to-tiff-custom-image.tiff", slides.export.SaveFormat.TIFF, opts)

Python PowerPoint 到具有自定義像素格式的 TIFF

Aspose.Slides for Python 還允許您設置生成的 TIFF 圖像的像素格式。這可以通過執行以下步驟來實現。

  • 使用 Presentation 類加載 PPT/PPTX 演示文稿。
  • 創建 TiffOptions 類的實例。
  • 使用 TiffOptions.pixelformat 屬性設置 所需像素格式
  • 使用 Presentation.save(string, SaveFormat.TIFF, TiffOptions) 方法將演示文稿轉換為 TIFF。

以下代碼示例顯示瞭如何使用 Python 自定義 PPT 到 TIFF 轉換中的像素格式。

import aspose.slides as slides

# 負載演示
presentation = slides.Presentation("presentation.pptx")

# 實例化 TiffOptions 類
opts = slides.export.TiffOptions()

# 設置像素格式
opts.pixel_format = slides.export.ImagePixelFormat.FORMAT8BPP_INDEXED

# 將 PPT 另存為 TIFF
presentation.save("ppt-to-tiff-pixel-format.tiff", slides.export.SaveFormat.TIFF, opts)

獲得免費許可證

通過申請臨時許可,您可以在沒有評估限制的情況下使用 Aspose.Slides for Python。

結論

在本文中,您學習瞭如何在 Python 中將 PowerPoint PPT 轉換為 TIFF。此外,您還了解瞭如何自定義圖像大小、包括隱藏幻燈片、設置壓縮類型以及定義生成的 TIFF 的像素格式。此外,您可以訪問 文檔 來探索 Aspose.Slides for Python 的其他功能。此外,您可以將您的問題或疑問發佈到我們的論壇

也可以看看