Convert PowerPoint PPT to JPG in Python
About PowerPoint to JPG Conversion
With Aspose.Slides .NET API you can convert PowerPoint PPT or PPTX presentation to JPG image in Python. It is also possible to convert PPT/PPTX to BMP, PNG or SVG in Python. With this features it’s easy to implement your own presentation viewer, create the thumbnail for every slide. This may be useful if you want to protect presentation slides from copywriting, demonstrate presentation in read-only mode. Aspose.Slides allows to convert the whole presentation or a certain slide into image formats.
Convert PowerPoint PPT/PPTX to JPG
Here are the steps to convert PPT/PPTX to JPG:
- Create an instance of Presentation class.
- Get the slide object of ISlide type from Presentation.Slides collection.
- Create the thumbnail of each slide and then convert it into JPG. ISlide.GetThumbnail(float scaleX, float scaleY) method is used to get a thumbnail of a slide, it returns Bitmap object as a result. GetThumbnail method has to be called from the needed slide of ISlide type, the scales of the resulting thumbnail are passed into the method.
- After you get the slide thumbnail, call Image.Save(string filename, ImageFormat format) method from the thumbnail object. Pass the resulting file name and the image format into it.
import aspose.slides as slides
import aspose.pydrawing as drawing
pres = slides.Presentation("pres.pptx")
for sld in pres.slides:
bmp = sld.get_thumbnail(1, 1)
bmp.save("Slide_{num}.jpg".format(num=str(sld.slide_number)), drawing.imaging.ImageFormat.jpeg)
Convert PowerPoint PPT/PPTX to JPG with Customized Dimensions
To change the dimension of the resulting thumbnail and JPG image, you can set the ScaleX and ScaleY values by passing them into the ISlide.GetThumbnail(float scaleX, float scaleY) method:
import aspose.slides as slides
import aspose.pydrawing as drawing
pres = slides.Presentation("pres.pptx")
desiredX = 1200
desiredY = 800
scaleX = (float)(1.0 / pres.slide_size.size.width) * desiredX
scaleY = (float)(1.0 / pres.slide_size.size.height) * desiredY
for sld in pres.slides:
bmp = sld.get_thumbnail(scaleX, scaleY)
bmp.save("Slide_{num}.jpg".format(num=str(sld.slide_number)), drawing.imaging.ImageFormat.jpeg)
Render Comments when saving Presentation into Image
Aspose.Slides for Python via .NET provides a facility that allows you to render comments in a presentation’s slides when you are converting those slides into images. This Python code demonstrates the operation:
import aspose.slides as slides
import aspose.pydrawing as drawing
pres = slides.Presentation("pres.pptx")
bmp = drawing.Bitmap(740, 960)
opts = slides.export.RenderingOptions()
opts.notes_comments_layouting.notes_position = slides.export.NotesPositions.BOTTOM_TRUNCATED
opts.notes_comments_layouting.comments_area_color = drawing.Color.red
opts.notes_comments_layouting.comments_area_width = 200
opts.notes_comments_layouting.comments_position = slides.export.CommentsPositions.RIGHT
graphics = drawing.Graphics.from_image(bmp)
pres.slides[0].render_to_graphics(opts, graphics)
bmp.save("OutPresBitmap.jpg", drawing.imaging.ImageFormat.jpeg)
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.
See also
See other options to convert PPT/PPTX into image like: