In this simple topic, we will demonstrate to you how to convert SVG to Presentation using C# without any reliance on PowerPoint. Good thing is that you do not need third-party software or an Interop library for converting SVG to PPTX in C#. The application can be used in any of the .NET configured environments inside Windows, Linux or macOS provided sample code can run seamlessly on all .NET platforms.
Steps to Export SVG to PPTX in C#
- Configure your application to add Aspose.Slides for .NET package from NuGet.org
- Create an instance of a Presentation class to create a default presentation
- Access the first default slide inside the presentation slides collection
- Read the SVG file content as a string and insert that into the presentation images collection
- Add a picture frame shape inside the selected slide with added SVG image
- Save the presentation with an SVG image on the disk
By using the aforementioned steps in C# saving SVG as PPT presentation can be easily done. The process is commenced by creating an instance of the Presentation class and accessing the default first slide from the slides collection. Then SVG file content is read as a string from the disk and added to an IPPImage inside the presentation images collection. Finally, a picture frame shape is added inside the slide by using the added SVG and the presentation is saved on the disk.
Code to Convert SVG to PPTX in C#
using Aspose.Slides; | |
namespace TestSlides | |
{ | |
public class InsertSVG | |
{ | |
public static void AddSvgToSlide() | |
{ | |
string filesPath = @"/Documents/KnowledgeBase/TestData/"; | |
License license = new License(); | |
license.SetLicense(filesPath + "Conholdate.Total.Product.Family.lic"); | |
//Create a new presentation to insert an SVG image | |
Presentation SvgPresentation = new Presentation(); | |
//Access the first default slide of the presentation | |
ISlide slide = SvgPresentation.Slides[0]; | |
//Load the SVG file content and add that to the presentation image collection | |
var svgContent = System.IO.File.ReadAllText(filesPath + "410.svg"); | |
ISvgImage svgImage = new SvgImage(svgContent); | |
IPPImage ppSVGImage = SvgPresentation.Images.AddImage(svgImage); | |
//Insert the SVG inside a picture frame shape | |
slide.Shapes.AddPictureFrame(ShapeType.Rectangle, 0, 0, ppSVGImage.Width, ppSVGImage.Height, ppSVGImage); | |
//Save the presentation with an SVG image | |
SvgPresentation.Save(filesPath + "PresWithSVG.pptx", Aspose.Slides.Export.SaveFormat.Pptx); | |
} | |
} | |
} |
This tutorial explains how to insert SVG in Presentation using C#. If you want to learn about adding a table inside the PowerPoint presentation, refer to the article on how to create a table in PowerPoint using C#.