Convert PPT to JPG in Python

Convert PPT to JPG in Python

While working with PowerPoint presentations in your Python applications, you may need to generate thumbnails for a PPT. For example, while creating a slideshow or a presentation manipulation tool. In this article, you will learn how to generate thumbnails by converting a PPT to JPG images in Python. We will also cover how to generate JPG images having custom dimensions and render slide notes and comments.

TIP: You may want to check out Aspose FREE PowerPoint to JPG converter.

Python PPT to JPG Converter

To convert PowerPoint presentations to JPG images, we will utilize Aspose.Slides for Python via .NET. It is a powerful library to implement presentation manipulation features in Python. Using the library, you can create, modify and convert the presentations seamlessly. Use the following pip command to install the library from PyPI.

> pip install aspose.slides

Convert a PPT to JPG in Python

The following are the steps to convert a PPT presentation to JPG images in Python.

  • First, load the presentation file using Presentation class.
  • Then, iterate through the slides using Pesentation.slides collection.
    • Get reference of each ISlide in the collection using slide’s index.
    • Finally, use ISlide.get_thumbnail().save(string, ImageFormat.jpeg) method to convert a slide to JPG image.

The following code sample shows how to convert a PowerPoint PPTX to JPG in Python.

The following screenshot shows the resultant JPG image of first slide in the presentation.

Convert PowerPoint PPT to JPG in Python
Resultant JPG Image

PPT to JPG – Customize Image Dimensions

You can also customize the dimensions of the resultant JPG images by providing width and height. Also, you can scale the images as per your requirements. The following steps demonstrate how to convert PPT to JPG with customized dimensions and scaling.

  • First, load the presentation file using Presentation class.
  • Create two variables to set width and height of JPG images.
  • Set X and Y scaling of the images using the specified width and height.
  • Iterate through the slides using Pesentation.slides collection.
    • Get reference of each ISlide from the collection using slide’s index.
    • Convert slide to JPG using ISlide.get_thumbnail(scaleX, scaleY).save(string, ImageFormat.jpeg) method.

The following code sample shows how to generate PPT thumbnails with customized scaling and dimensions in Python.

Include Notes and Comments – Python PPT to JPG

MS PowerPoint also allows you to write comments and notes for each slide in the presentation. By default, the comments and notes are not rendered in PPT to JPG conversion. However, you can include them in the resultant JPG images following the below steps.

  • First, load the presentation file using Presentation class.
  • Create a Bitmap object by specifying width and height of resultant images.
  • Create an object of RenderingOptions class.
  • Specify position for notes using RenderingOptions.notes_comments_layouting.notes_position property.
  • To include comments, use RenderingOptions.notes_comments_layouting.comments_position property.
  • Iterate through the slides in Pesentation.slides collection.
    • Generate graphics object from Bitmap using Graphics.from_image(Bitmap) method.
    • Render the slide to graphics using Presentation.slides[index].render_to_graphics(RenderingOptions, graphics) method.
    • Save slide as JPG using Bitmap.save(string, ImageFormat.jpeg) method.

The following code sample shows how to render notes and comments in PPT to JPG conversion.

The following screenshot shows the resultant JPG image that contains slide notes and comments.

Convert a PPT to JPG with Comments and Notes in Python
PPT to JPG with Slide Notes and Comments

Get a Free License

You can use Aspose.Slides for Python via .NET without evaluation limitations by getting a temporary license.

Conclusion

In this article, you have learned how to convert PowerPoint PPT or PPTX to JPG images in Python. In addition, you have seen how to generate JPG images with custom dimensions and scaling. We have also covered how to include slide notes and comments in PPT to JPG conversion. Aspose.Slides for Python via .NET also provides a wide range of features that you can explore using the documentation. In case you would have any questions, contact us on our forum.

See Also