In this tutorial, we will focus on how to convert SVG to Presentation using Python without any reliance on PowerPoint. The application can be utilized inside any of the .NET core and Python configured environments in operating systems like Windows, Linux or macOS for converting SVG to PPTX in Python.
Steps to Export SVG to PPTX in Python
- Configure the environment to use Aspose.Slides for Python via .NET in your application to convert SVG to a presentation
- Create a default presentation using an instance of the Presentation class
- Load the first slide from the presentation’s slides collection
- Open the SVG file, read its content as a string and insert that into the presentation images collection
- Insert a picture frame inside the slide with added SVG image using an instance of IPictureFrame
- Save the PPTX file with an SVG image on the disk
The above simple steps in Python export SVG as PPT presentation using a simple API interface. We will start by creating a default presentation using an instance of the Presentation class and accessing the first default slide from the presentation’s slides collection. We will then load and read the SVG file content as a string from the disk and add that to an IPPImage inside the presentation images collection. Finally, by using an IPictureFrame class instance, a picture frame shape will be added that will utilize the added SVG file before saving the resultant presentation on the disk.
Code to Convert SVG to PPTX in Python
import aspose.slides as slides | |
filepath = "C://Words//" | |
#Applying the licence for Aspose.Slides to convert SVG to PPTX | |
svgtoSlidesLicense = slides.License() | |
svgtoSlidesLicense.set_license(filepath + "Conholdate.Total.Product.Family.lic") | |
# Make an empty presentation using the Presentation class object | |
with slides.Presentation() as sampleSvgPres: | |
#Access the first slide of the newly created presentation | |
slideForSvg = sampleSvgPres.slides[0] | |
#Load the SVG file content and insert that inside the presentation image collection | |
with open(filepath + "410.svg", 'r') as svgfile: | |
svgContent = svgfile.read().rstrip() | |
ppSVGImage = slides.SvgImage(svgContent) | |
#Add an SVG Image from the disk inside the images collection of the presentation | |
svgImageForSlide = sampleSvgPres.images.add_image(ppSVGImage) | |
#Insert a picture frame inside the shapes collection of the slide | |
slideForSvg.shapes.add_picture_frame(slides.ShapeType.RECTANGLE, 0, 0, 720, 540, svgImageForSlide) | |
#Save the presentation in PPTX format with an SVG image on the disk | |
slideForSvg.save(filepath + "PresentationWithSvg.pptx", slides.export.SaveFormat.PPTX) | |
print("Process Completed") | |
This topic explained how to insert SVG in Presentation using Python. If you are interested to learn about inserting a table inside the PowerPoint slide, refer to the article on how to create a table in PowerPoint using Python.