Convert PPT, PPTX, and ODP to JPG in Python
Overview
Converting PowerPoint and OpenDocument presentations to JPG images helps with sharing slides, optimizing performance, and embedding content into websites or applications. Aspose.Slides for Python allows you to transform PPTX, PPT, and ODP files into high-quality JPEG images. This guide explains different methods for conversion.
With these features, it’s easy to implement your own presentation viewer and create a thumbnail for every slide. This may be useful if you want to protect presentation slides from copying or demonstrate the presentation in read-only mode. Aspose.Slides allows you to convert the whole presentation or a specific slide into image formats.
Convert Presentation Slides to JPG Images
Here are the steps to convert a PPT, PPTX, or ODP file to JPG:
- Create an instance of the Presentation class.
- Get the slide object of the Slide type from the Presentation.slides collection.
- Create an image of the slide using the Slide.get_image(scale_x, scale_y) method.
- Call the IImage.save(filename, format) method on the image object. Pass the output file name and image format as arguments.
import aspose.slides as slides
scale_x = 1
scale_y = scale_x
with slides.Presentation("PowerPoint_Presentation.ppt") as presentation:
for slide in presentation.slides:
with slide.get_image(scale_x, scale_y) as thumbnail:
# Save the image to disk in JPEG format.
file_name = f"Slide_{slide.slide_number}.jpg"
thumbnail.save(file_name, slides.ImageFormat.JPEG)
Convert Slides to JPG with Customized Dimensions
To change the dimensions of the resulting JPG images, you can set the image size by passing it into the Slide.get_image(image_size) method. This allows you to generate images with specific width and height values, ensuring that the output meets your requirements for resolution and aspect ratio. This flexibility is particularly useful when generating images for web applications, reports, or documentation, where precise image dimensions are required.
import aspose.slides as slides
import aspose.pydrawing as pydrawing
image_size = pydrawing.Size(1200, 800)
with slides.Presentation("PowerPoint_Presentation.pptx") as presentation:
for slide in presentation.slides:
# Create a slide image of the specified size.
with slide.get_image(image_size) as thumbnail:
# Save the image to disk in JPEG format.
file_name = f"Slide_{slide.slide_number}.jpg"
thumbnail.save(file_name, slides.ImageFormat.JPEG)
Render Comments when Saving Slides as Images
Aspose.Slides for Python provides a feature that allows you to render comments on a presentation’s slides when converting them into JPG images. This functionality is particularly useful for preserving annotations, feedback, or discussions added by collaborators in PowerPoint presentations. By enabling this option, you ensure that comments are visible in the generated images, making it easier to review and share feedback without needing to open the original presentation file.
Let’s say we have a presentation file, “sample.pptx,” with a slide that contains comments:
The following Python code converts the slide to a JPG image while preserving the comments:
import aspose.slides as slides
import aspose.pydrawing as pydrawing
scale_x = 1
scale_y = scale_x
with slides.Presentation("sample.pptx") as presentation:
# Set options for the slide comments.
comments_options = slides.export.NotesCommentsLayoutingOptions()
comments_options.comments_position = slides.export.CommentsPositions.RIGHT
comments_options.comments_area_width = 200
comments_options.comments_area_color = pydrawing.Color.dark_orange
options = slides.export.RenderingOptions()
options.slides_layout_options = comments_options
# Convert the first slide to an image.
with presentation.slides[0].get_image(options, scale_x, scale_y) as thumbnail:
thumbnail.save("Slide_1.jpg", slides.ImageFormat.JPEG)
The result:
See also
See other options for converting PPT, PPTX, or ODP to images, such as:
- Convert PowerPoint to GIF
- Convert PowerPoint to PNG
- Convert PowerPoint to TIFF
- Convert PowerPoint to SVG
Tip
Aspose provides a FREE Collage web app. Using this online service, you can merge JPG to JPG or PNG to PNG images, create photo grids, and so on.
Using the same principles described in this article, you can convert images from one format to another. For more information, see these pages: convert image to JPG; convert JPG to image; convert JPG to PNG, convert PNG to JPG; convert PNG to SVG, convert SVG to PNG.