Python: Convert PowerPoint Presentation to PDF

PowerPoint presentations provide visual engaging content delivery with dynamic multimedia elements. However, when it comes to distribution, converting PowerPoint presentations to PDF files offers distinct advantages. PDF documents ensure consistent document appearance across different platforms and devices, while also providing enhanced protection for document content, enabling users to extensively share presentations while ensuring the integrity and security of the content. This article is going to show how to use Spire.Presentation for Python to convert PowerPoint presentations to PDF files in Python programs.

Install Spire.Presentation

This scenario requires Spire.Presentation for Python and plum-dispatch v1.7.4. They can be easily installed in your Windows through the following pip commands.

pip install Spire.Presentation

If you are unsure how to install, please refer to this tutorial: How to Install Spire.Presentation for Python on Windows

Convert a PowerPoint Presentations to a PDF Document

Spire.Presentation for Python provides the Presentation.SaveToFile(fileName: str, fileFormat: FileFormat) that enables the conversion of a presentation file to a PDF document. Below are the detailed steps to perform this operation.

  • Create an object of Presentation class.
  • Load a presentation file using Presentation.LoadFromFile() method.
  • Save the presentation to a PDF document using Presentation.SaveToFile(fileName: str, fileFormat: FileFormat) method.
  • Python
from spire.presentation import *
from spire.presentation.common import *

# Create an object of Presentation class
presentation = Presentation()

# Load a presentation file
presentation.LoadFromFile("Sample.pptx")

# Convert the presentation file to PDF and save it
presentation.SaveToFile("output/PresentationToPDF.pdf", FileFormat.PDF)
presentation.Dispose()

Python: Convert PowerPoint Presentation to PDF

Convert PowerPoint Presentation to PDF and Set the Page Size

During the conversion, users can also use the Presentation.SlideSize.Type property to set the slide size, thereby determining the page size of the resulting PDF document. Here are the detailed steps for this operation.

  • Create an object of Presentation class.
  • Load a presentation file using Presentation.LoadFromFile() method.
  • Set the slide size to A4 using Presentation.SlideSize.Type property.
  • Save the presentation to a PDF document using Presentation.SaveToFile(file: str, fileFormat: FileFormat) method.
  • Python
from spire.presentation import *
from spire.presentation.common import *

# Create an object of Presentation class
presentation = Presentation()

# Load a presentation file
presentation.LoadFromFile("Sample.pptx")

# Change the side size to A4
presentation.SlideSize.Type = SlideSizeType.A4

# Convert the presentation file to PDF and save it
presentation.SaveToFile("output/PresentationToPDFA4.pdf", FileFormat.PDF)
presentation.Dispose()

Python: Convert PowerPoint Presentation to PDF

Convert a Presentation Slide to a PDF Document

Spire.Presentation for Python also supports converting a single slide from a presentation file to a PDF document. The detailed steps for this operation are as follows.

  • Create an object of Presentation class.
  • Load a presentation file using Presentation.LoadFromFile() method.
  • Get a slide using Presentation.Slides[] property.
  • Save the slide as a PDF document using ISlde.SaveToFile(file: str, fileFormat: FileFormat) method.
  • Python
from spire.presentation import *
from spire.presentation.common import *

# Create an object of Presentation class
presentation = Presentation()

# Load a presentation file
presentation.LoadFromFile("Sample.pptx")

# Get a slide
slide = presentation.Slides[1]

# Save the slide as an PDF file
slide.SaveToFile("output/SlideToPDF.pdf", FileFormat.PDF)

Python: Convert PowerPoint Presentation to PDF

Apply for a Temporary License

If you'd like to remove the evaluation message from the generated documents, or to get rid of the function limitations, please request a 30-day trial license for yourself.