How to Convert PowerPoint to Images in Python (PNG, JPG, BMP, SVG)

How to Convert PowerPoint to Images in Python (PNG, JPG, BMP, SVG)

·

5 min read

PowerPoint allows users to save slides as various image formats, such as PNG, JPG, BMP, and more. Converting slides to images makes it easier and faster to share your ideas—whether you're sending them to clients or uploading them online. While tools like MS PowerPoint offer built-in conversion features, repeatedly opening files and manually converting slides can be time-consuming. Fortunately, using Python to convert PowerPoint to images (including PNG, JPG, BMP, and SVG) provides a more efficient solution. In this article, we'll guide you through the process with detailed steps and code examples, helping you streamline this task effortlessly!


Python Library to Convert PowerPoint to Images

There are some PowerPoint converts that can finish the task, such as Smallpdf, an online PDF editor. However, online tools often come with security concerns and require uploading and downloading files, which can be inconvenient. To address these issues, third-party Python libraries like Spire.Presentation (Spire.Presentation for Python) offers a reliable alternative. This tool enables seamless PowerPoint format conversion, including exporting to images, PDFs, HTML, and more, all simply and efficiently since Spire.Presentation operates offline within the Python editor, it eliminates the risks and limitations associated with online tools.

You can install it using the pip command: pip install Spire.Presentation.

How to Convert PowerPoint to PNG, JPG, and BMP

After the preparation, let’s check out the main topic. Whether it is for printing, sharing, or archiving, exporting PowerPoint presentations as images is a good choice. With the ISlide.SaveAsImage() method provided by Spire.Presentation, you can easily save presentations as images. In this section, we will guide you through how to convert PowerPoint slides as PNG, JPG, and BMP in detail.

Steps to transform PowerPoint slides to PNG, JPG, and BMP:

  • Create an object of the Presentation class, and use the Presentation.LoadFromFile() method to read a PowerPoint presentation.

  • Loop through all slides in the document.

    • Convert the current slide to an image stream with the ISlide.SaveAsImage() method.

    • Save the image stream to PNG, JPG, or BMP by calling the Stream.Save() method.

Here is the code example of converting PowerPoint slides to PNG:

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

# Create a Presentation object
presentation = Presentation()

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

# Loop through the slides in the presentation
for i, slide in enumerate(presentation.Slides):
    # Specify the output file name
    fileName = "Output/ToImage_" + str(i) + ".png"
    # Save each slide as a PNG image
    image = slide.SaveAsImage()
    image.Save(fileName)
    image.Dispose()

# Release the resource
presentation.Dispose()

Convert PowerPoint to PNG, JPG, and BMP with Specific Sizes

If shared, the file can be kept at its original size for easy access by the recipient. Alternatively, reducing its size slightly can make uploading faster and require less storage space. By calling the Islide.SaveAsImageByWH() method, you can control the sizes when converting PowerPoint presentations to images.

Steps to convert PowerPoint slides to images while controlling the sizes:

  • Create a Presentation instance.

  • Loading a PowerPoint document from files using the Presentation.LoadFromFile() method.

  • Iterate through each slide in the PowerPoint presentation.

    • Save the current slide to an image stream with the Islide.SaveAsImageByWH() method.

    • Save the image stream as a PNG, JPG, or BMP file through the Stream.Save() method.

Below is the code example of converting PowerPoint slides to PNG with a size of 700 * 400 pixels:

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

# Create a Presentation object
presentation = Presentation()

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

# Loop through the slides in the presentation
for i, slide in enumerate(presentation.Slides):
    # Specify the output file name
    fileName = "Output/ToImage_" + str(i) + ".png"
    # Save each slide to a PNG image with a size of 700 * 400 pixels
    image = slide.SaveAsImageByWH(700, 400)
    image.Save(fileName)
    image.Dispose()

presentation.Dispose()

Convert PowerPoint to PNG JPG BMP with Specified Sizes

How to Convert PowerPoint to SVG

Unlike PNG and JPG, SVG is a vector graphic format that can be scaled infinitely without losing clarity, making it ideal for web design. Since SVG stores data differently from bitmap images like PNG, JPG, and BMP, a specialized conversion method named Islide.SaveToSVG() is required to convert PowerPoint slides into this format. Check out the detailed guide below.

Steps to convert PowerPoint to SVG:

  • Create an instance of the Presentation class.

  • Specify the file path of the source PowerPoint presentation with the Presentation.LoadFromFile() method.

  • Set the IsNoteRetained property to True to maintain notes when converting.

  • Loop through each slide in the document.

  • Save each slide as an SVG stream using the Islide.SaveToSVG() method.

  • Save the SVG stream to an SVG file through the Stream.Save() method.

Below is an example of converting PowerPoint slides to SVG files:

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

# Create a Presentation object
presentation = Presentation()

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

# Enable the IsNoteRetained property to retain notes when converting the presentation to SVG files
presentation.IsNoteRetained = True

# Loop through the slides in the presentation
for i, slide in enumerate(presentation.Slides):
    # Specify the output file name
    fileName = "SVG/ToSVG_" + str(i) + ".svg"
    # Save each slide to an SVG image
    svgStream = slide.SaveToSVG()
    svgStream.Save(fileName)

presentation.Dispose()

Convert PowerPoint to SVG Files

The Conclusion

This article provides a comprehensive guide on how to convert PowerPoint to images using Python, covering formats like PNG, JPG, BMP, and SVG. It also explains how to control image size when converting to the first three formats. By following this guide, you'll find that converting slides to images becomes simple and efficient. We hope this article helps you streamline your tasks!