Convert PPT and PPTX to JPG in Python
Introduction
Aspose.Slides for Python via Java lets you convert PowerPoint and OpenDocument presentations (PPT, PPTX, and ODP) into JPEG images. You can export every slide or a selected slide to create thumbnails, build a presentation viewer, or embed slide previews in a website or application.
Convert PowerPoint PPT/PPTX to JPG
- Load the presentation with Presentation.
- Retrieve the slides using getSlides.
- Call Slide.getImage with horizontal and vertical scale factors to render each slide.
- Save each rendered image as JPEG using ImageFormat.Jpeg, then release the image resources.
Note
Exporting to JPG creates a separate image for each slide. Save the rendered image rather than saving the presentation directly to an image format.import jpype
import asposeslides
if not jpype.isJVMStarted():
jpype.startJVM()
from asposeslides.api import ImageFormat, Presentation
presentation = Presentation("presentation.pptx")
try:
for slide in presentation.getSlides():
slide_image = slide.getImage(1.0, 1.0)
try:
slide_image.save(f"Slide_{slide.getSlideNumber()}.jpg", ImageFormat.Jpeg)
finally:
slide_image.dispose()
finally:
presentation.dispose()
Convert PowerPoint PPT/PPTX to JPG with Customized Dimensions
Calculate horizontal and vertical scale factors from the desired pixel dimensions and the original slide size, then pass them to Slide.getImage. The following example targets a 1200 × 800 image for each slide.
Using different scale factors can stretch the slide. To preserve its aspect ratio, use the same scale factor for both axes; the resulting width and height will then follow the original slide proportions.
import jpype
import asposeslides
if not jpype.isJVMStarted():
jpype.startJVM()
from asposeslides.api import ImageFormat, Presentation
presentation = Presentation("presentation.pptx")
try:
desired_width = 1200
desired_height = 800
slide_size = presentation.getSlideSize().getSize()
scale_x = desired_width / slide_size.getWidth()
scale_y = desired_height / slide_size.getHeight()
for slide in presentation.getSlides():
slide_image = slide.getImage(scale_x, scale_y)
try:
slide_image.save(f"Slide_{slide.getSlideNumber()}.jpg", ImageFormat.Jpeg)
finally:
slide_image.dispose()
finally:
presentation.dispose()
Render Comments When Saving Slides as Images
Use NotesCommentsLayoutingOptions to configure notes and comments, and apply the layout through RenderingOptions.setSlidesLayoutOptions. This example places notes at the bottom, truncating notes that do not fit, and displays comments on the right in a 200-pixel-wide area. It saves each rendered slide as a JPG image.
import jpype
import asposeslides
if not jpype.isJVMStarted():
jpype.startJVM()
from asposeslides.api import CommentsPositions, ImageFormat, NotesCommentsLayoutingOptions, NotesPositions, Presentation, RenderingOptions
from java.awt import Dimension
presentation = Presentation("presentation.pptx")
try:
layout_options = NotesCommentsLayoutingOptions()
layout_options.setNotesPosition(NotesPositions.BottomTruncated)
layout_options.setCommentsPosition(CommentsPositions.Right)
layout_options.setCommentsAreaWidth(200)
rendering_options = RenderingOptions()
rendering_options.setSlidesLayoutOptions(layout_options)
image_size = Dimension(740, 960)
for slide in presentation.getSlides():
slide_image = slide.getImage(rendering_options, image_size)
try:
slide_image.save(f"Slide_{slide.getSlideNumber()}.jpg", ImageFormat.Jpeg)
finally:
slide_image.dispose()
finally:
presentation.dispose()
FAQ
Can I convert multiple slides or presentations to JPG?
Yes. The examples loop through all slides and save one JPG per slide. To process multiple presentations, repeat the conversion for each input file and use separate output folders or unique file names to avoid overwriting images.
Are charts, SmartArt, tables, and shapes included in the images?
These objects are rendered as part of the slide. Make the fonts used by the presentation available in the conversion environment to reduce differences caused by font substitution.
How can I reduce memory usage when exporting large presentations?
Process images one at a time, release each image after saving it, and avoid unnecessarily large output dimensions. Memory requirements depend on the slide content and image size.