0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

PythonでPowerPoint (PPT/PPTX)をPDFに変換する

Last updated at Posted at 2024-10-18

PowerPointをPDF形式に変換すると、元のPowerPointファイルのレイアウト、フォント、色、画像を保持することができ、どのようなデバイス上で表示するときに一貫性を確保します。この記事では、PythonでPowerPointファイルをプログラムでPDFに変換する方法を紹介します。

Pythonライブラリのインストール

PowerPointからPDFへの変換には、サードパーティ製ライブラリSpire.Presentation for Pythonが必要です。これはpip経由でインストールできます:

pip install Spire.Presentation

または、以下のリンクから製品パッケージをダウンロードし、ローカルパスからインストールすることができます。

PythonでPowerPointプレゼンテーションをPDFに変換する

主なステップ:

1. Presentation クラスのオブジェクトを作成します。
2. Presentation.LoadFromFile() メソッドを使用して、PPTまたはPPTXファイルをロードします。
3. Presentation.SaveToFile(fileName: str, fileFormat: FileFormat) メソッドを使用して、PowerPointファイルをPDF文書に保存します。

Pythonのコード:

from spire.presentation import *
from spire.presentation.common import *

# PowerPointファイルを読み込む
presentation = Presentation()
presentation.LoadFromFile("Input.pptx")

# PowerPointファイルをPDFに保存する
presentation.SaveToFile("PowerPointToPDF.pdf", FileFormat.PDF)
presentation.Dispose()

PPTXtoPDF.png

Pythonで指定したスライドをPDFに変換する

主なステップ:

1. Presentation クラスのオブジェクトを作成します。
2. Presentation.LoadFromFile() メソッドを使用して、PPTまたはPPTXファイルをロードします。
3. Presentation.Slides[] プロパティを使用してスライドを取得します。
4. ISlde.SaveToFile(file: str, fileFormat: FileFormat) メソッドを使用してスライドをPDFに保存します。

Pythonのコード:

from spire.presentation import *
from spire.presentation.common import *

# PowerPointファイルを読み込む
presentation = Presentation()
presentation.LoadFromFile("InputR.pptx")

# 指定したスライドを取得する
slide = presentation.Slides[1]

# スライドをPDFに保存する
slide.SaveToFile("SlideToPDF.pdf", FileFormat.PDF)
presentation.Dispose()

Pythonライブラリは、PDFへの変換に加えて、HTMLへのPowerPointの変換、画像へのPowerPointの変換、および他の多くのPPT/PPTXファイル処理機能をサポートしています。詳しくは以下をご覧ください:

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?