Convert PowerPoint Slides to PNG in Python
Overview
Aspose.Slides for Python via .NET makes it straightforward to convert PowerPoint presentations to PNG. You load a presentation, iterate through its slides, render each one to a raster image, and save the result as PNG files. This is ideal for generating slide previews, embedding slides in web pages, or producing static assets for downstream processing.
Convert Slides to PNG
This section shows the simplest possible example of converting a PowerPoint presentation to PNG images using Aspose.Slides for Python via .NET.
Go through these steps:
- Instantiate the Presentation class.
- Get a slide from the
Presentation.slidescollection (see the Slide class). - Use the
Slide.get_imagemethod to generate a thumbnail of the slide. - Use the
Presentation.savemethod to save the slide thumbnail in PNG format.
This Python code shows how to convert a PowerPoint presentation to PNG:
import aspose.slides as slides
with slides.Presentation("presentation.pptx") as presentation:
for index, slide in enumerate(presentation.slides):
with slide.get_image() as image:
image.save(f"slide_{index}.png", slides.ImageFormat.PNG)
Convert Slides to PNG with Custom Dimensions
To export slides to PNG at a custom scale, call Slide.get_image with horizontal and vertical scale factors. These multipliers resize the output relative to the slide’s original dimensions—for example, 2.0 doubles both width and height. Use equal values for scale_x and scale_y to preserve the aspect ratio.
This Python code demonstrates the described operation:
import aspose.slides as slides
scale_x = 2
scale_y = scale_x
with slides.Presentation("presentation.pptx") as presentation:
for index, slide in enumerate(presentation.slides):
with slide.get_image(scale_x, scale_y) as image:
image.save(f"slide_{index}.png", slides.ImageFormat.PNG)
Convert Slides to PNG with Custom Size
If you want to generate PNG files at a specific size, pass your desired width and height values. The code below shows how to convert a PowerPoint to PNG while specifying the image size:
import aspose.slides as slides
import aspose.pydrawing as drawing
size = drawing.Size(960, 720)
with slides.Presentation("presentation.pptx") as presentation:
for index, slide in enumerate(presentation.slides):
with slide.get_image(size) as image:
image.save(f"slide_{index}.png", slides.ImageFormat.PNG)
Tip
You may want to try Aspose’s free PowerPoint-to-PNG converters—PPTX to PNG and PPT to PNG. They provide a live implementation of the process described on this page.FAQ
How can I export only a specific shape (e.g., chart or picture) rather than the whole slide?
Aspose.Slides supports generating thumbnails for individual shapes; you can render a shape to a PNG image.
Is parallel conversion supported on a server?
Yes, but don’t share a single presentation instance across threads. Use a separate instance per thread or process.
What are the trial-version limitations when exporting to PNG?
The evaluation mode adds a watermark to output images and enforces other restrictions until a license is applied.