How to Save Slide as SVG in C++

In this tutorial, we will explore how to Save Slide as SVG in C++. SVG is popular format while rendering images in browsers and using C++, you can convert PowerPoint Slide to SVG in few API calls.

Steps to Save Slide as SVG in C++

  1. Install Aspose.Slides for C++ with NuGet package Manager tool
  2. include reference to Aspose::Slides namespace
  3. Load the presentation file for saving slide as SVG using Presentation Class instance
  4. Use the WriteAsSvg method to convert slide to SVG

You can easily convert PPTX to SVG in C++ using few lines of code and with no reliance or dependency on Microsoft Interop or PowerPoint.

Code to Convert Slide to SVG in C++

#pragma once
#include <DOM/Presentation.h>
#include <DOM/ISlide.h>
#include <DOM/ISlideCollection.h>
#include <Util/License.h>
#include <Export/SaveFormat.h>
#include <system/io/file.h>
#include <system/io/memory_stream.h>
#include <iostream>
#include <system/enumerator_adapter.h>
#include <system/console.h>
#include <system/string.h>
#include <system/io/file.h>
#include <system/io/file_mode.h>
#include <system/io/file_stream.h>
#include <system/io/memory_stream.h>
#include <system/math.h>
#include <system/special_casts.h>
#include <system/collections/dictionary.h>
#include <drawing/graphics.h>
#include <drawing/bitmap.h>
#include <system/io/file_stream.h>
using namespace Aspose::Slides;
using namespace Aspose::Slides::Export;
using namespace System;
using namespace System::IO;
class ConvertToSVG {
public:
static void ConverSlidesSVGImage()
{
// Instantiate Presentation class to load the presentation
SharedPtr<Presentation> pres = MakeObject<Presentation>(u"input.pptx");
// Instantiate the Slide class to access the first slide
SharedPtr<ISlide> slide = pres->get_Slides()->idx_get(0);
// Create a memory stream object to hold the exported SVG
SharedPtr<MemoryStream> SvgStream = MakeObject<MemoryStream>();
// Save Slide as SVG image in memory stream
slide->WriteAsSvg(SvgStream);
SvgStream->set_Position(0);
// Save SVG in memory stream to disc
try
{
SharedPtr<Stream> fileStream = File::OpenWrite(u"saved.svg");
ArrayPtr<uint8_t> buffer = System::MakeObject<Array<uint8_t>>(8 * 1024, 0);
int32_t len;
while ((len = SvgStream->Read(buffer, 0, buffer->get_Length())) > 0)
{
fileStream->Write(buffer, 0, len);
}
}
catch (Exception e)
{
}
SvgStream->Close();
}
};

Previously, we learnt How to Covert PowerPoint Presentation to XPS Using C++. Whereas in the above example we have seen how to export Slide as SVG using C++.

 English