Convert PowerPoint PPTX or PPT to PDF with Python

Alice Yang
3 min readOct 8, 2023

--

Convert PowerPoint PPTX or PPT to PDF with Python
Convert PowerPoint PPTX or PPT to PDF with Python

PowerPoint presentations are widely used for delivering information and engaging audiences in various professional and academic settings. However, sharing PowerPoint presentations can sometimes be problematic, as they may not retain their original formatting on different devices or operating systems. One effective solution to this issue is to convert the PowerPoint presentations to the universally accessible PDF (Portable Document Format) format. In this article, we will explore how to convert PowerPoint presentations in PPTX or PPT format to PDF using Python.

We will discuss the following topics:

Python Library to Convert PowerPoint to PDF

To convert PowerPoint files to PDFs with Python, we can use the Spire.Presentation for Python library.

Spire.Presentation for Python is a feature-rich and user-friendly library that enables creating, reading, editing, and converting PowerPoint presentations within Python applications. With this library, you can perform a wide range of manipulations on PowerPoint presentations, including adding text or images, inserting shapes, creating tables and charts, adding or deleting slides, hiding or showing slides, merging or splitting presentations, encrypting or decrypting presentations, adding watermarks, inserting videos and audios, adding comments and many more. In addition, you are also able to convert PowerPoint presentations to various file formats, such as PDF, images, HTML, SVG, ODP, OFD, and XPS.

You can install Spire.Presentation for Python from PyPI using the following pip command:

pip install Spire.Presentation

For more detailed information about the installation, you can check this official documentation: How to Install Spire.Presentation for Python in VS Code.

Convert an Entire PowerPoint Presentation to PDF with Python

The Presentation.SaveToFile(str, FileFormat) function provided by Spire.Presentation for Python enables you to convert PowerPoint presentations to various file formats, including PDF, HTML, ODP, DPS, DPT, PCL, PS, XPS, and more.

Here is a simple example that shows how to convert a PowerPoint presentation in PPTX or PPT format to PDF using Python and Spire.Presentation for Python:

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

# Create a Presentation object
presentation = Presentation()
# Load a PowerPoint presentation in PPTX format
presentation.LoadFromFile("Sample.pptx")
# Or load a PowerPoint presentation in PPT format
#presentation.LoadFromFile("Sample.ppt")

# Convert the presentation to PDF format
presentation.SaveToFile("PresentationToPDF.pdf", FileFormat.PDF)
presentation.Dispose()

Convert a Specific PowerPoint Slide to PDF with Python

Converting a specific PowerPoint slide to PDF is helpful when you want to share only a specific slide of your presentation with others. To accomplish this task, you can use the ISlide.SaveToFile(str, FileFormat) function.

Here is a simple example that shows how to convert a specific slide of a PPTX or PPT file to PDF using Python and Spire.Presentation for Python:

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

# Create a Presentation object
presentation = Presentation()
# Load a PowerPoint presentation in PPTX format
presentation.LoadFromFile("Sample.pptx")
# Or load a PowerPoint presentation in PPT format
#presentation.LoadFromFile("Sample.ppt")

# Get the first slide using its index
slide = presentation.Slides[0]

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

Conclusion

This article demonstrated how to convert a PowerPoint presentation or a specific PowerPoint slide to PDF using Python. We hope you can find it helpful.

Helpful Links

Trial License | Forum Support

--

--

Alice Yang

Skilled senior software developers with five years of experience in all phases of software development life cycle using .NET, Java and C++ languages.