In this simple tutorial, we will show you how to save Slide as SVG in C# without any reliance on PowerPoint. Good thing is that you do not need Microsoft PowerPoint or Interop for converting PPTX to SVG in C#. Moreover, the provided sample code can run seamlessly on all .NET platforms.
Steps to Export PPTX to SVG in C#
- Download Aspose.Slides for .NET package from NuGet.org
- Use Aspose.Slides, Aspose.Slides.Export, System.Drawing and System.IO namespaces for converting PPTX to SVG in C#
- Use SetLicense method to apply API license and use all features
- Using Presentation class, load the PPTX to convert slide to SVG
- Iterate through presentation slides to export slide as SVG
- Save slide as SVG on disk
Earlier, we have looked into how to convert PPTX to XPS using C# in another how-to topic. However, this topic describes the steps in C# for PowerPoint to SVG conversion. Good thing is that you do not need Microsoft PowerPoint or Interop for converting PPTX to SVG in C# and code seamlessly on all .NET based platforms.
Code to Export PPTX to SVG in C# without Interop
using System; | |
using System.Drawing; | |
using System.IO; | |
using Aspose.Slides; | |
using Aspose.Slides.Export; | |
namespace SlidesWatermark | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
string PathForPptFile = @"Y:\Downloads\"; | |
// Setting Product License | |
License license = new License(); | |
license.SetLicense(PathForPptFile + "Conholdate.Total.Product.Family.lic"); | |
// Load the presentation to convert Slide to SVG in C# | |
using (Presentation PptxToSVG = new Presentation("ExportPptxToSVG.pptx")) | |
{ | |
for (var index = 0; index < PptxToSVG.Slides.Count; index++) | |
{ | |
// Acces slides to export Slide as SVG using C# | |
ISlide SlideToSVG = PptxToSVG.Slides[index]; | |
using (FileStream fileStream = new FileStream($"slide-{index}.svg", FileMode.Create, FileAccess.Write)) | |
{ | |
// Save Slide as SVG in C# | |
SlideToSVG.WriteAsSvg(fileStream); | |
} | |
} | |
} | |
} | |
} | |
} |
The example can be used in ASP.NET web application, Windows Forms application and Console based applications. You may use your local work machine or on any server having .NET Framework installed.