How to Save an SVG Image from a PowerPoint Presentation as an SVG File in C++?

Hi Team,
I am using aspose slides for cpp. There is a svg inserted in ppt. I want to be able to extract that picture as svg file. I have tried using IImage->Save(imagefilePath.svg); This seems to work for .png but doesnt work for .svg

Thanks

@pankajku

To extract an SVG image from a PowerPoint presentation using Aspose.Slides for C++, you will need to use the appropriate method to write the shape as an SVG file. The method you mentioned, IImage->Save(imagefilePath.svg);, is not suitable for SVG files.

Instead, you should access the specific shape within the slide and use the writeAsSvg method to save it as an SVG file. Here’s a code example to illustrate how to do this:

#include <aspose.slides.h>
#include <iostream>
#include <fstream>

using namespace Aspose::Slides;

int main() {
    // Load the presentation
    System::SharedPtr<Presentation> presentation = System::MakeObject<Presentation>(u"TestExportShapeToSvg.pptx");

    // Specify the output SVG file name
    const String outSvgFileName = u"SingleShape.svg";

    // Create a file output stream for the SVG file
    std::ofstream stream(outSvgFileName.ToUtf8String().c_str(), std::ios::out | std::ios::binary);
    
    if (stream.is_open()) {
        try {
            // Write the first shape of the first slide as SVG
            presentation->get_Slides()->idx_get(0)->get_Shapes()->idx_get(0)->writeAsSvg(stream);
        } catch (const std::exception& e) {
            std::cerr << "Error: " << e.what() << std::endl;
        } finally {
            stream.close();
        }
    } else {
        std::cerr << "Unable to open file for writing." << std::endl;
    }

    // Dispose of the presentation
    presentation->Dispose();
    return 0;
}

In this example, we load a PowerPoint presentation, access the first shape on the first slide, and write it to an SVG file using the writeAsSvg method. Make sure to replace "TestExportShapeToSvg.pptx" with the path to your actual PowerPoint file.

This approach should allow you to successfully extract and save the SVG image from your presentation. If you have any further questions or need additional assistance, feel free to ask!

@pankajku,
The following code example shows you how to extract an SVG image from a PowerPoint presentation:

auto presentation = new Presentation(u"sample.pptx");
auto shape = presentation->get_Slide(0)->get_Shape(0);

if (ObjectExt::Is<IPictureFrame>(shape))
{
    auto pictureFrame = ExplicitCast<IPictureFrame>(shape);
    auto svgImage = pictureFrame->get_PictureFormat()->get_Picture()->get_Image()->get_SvgImage();
    if (svgImage != nullptr)
    {
        auto svgData = svgImage->get_SvgData();

        auto fileStream = File::OpenWrite(u"output.svg");
        fileStream->Write(svgData, 0, svgData->Count());
        fileStream->Dispose();
    }
}
presentation->Dispose();

More examples: Picture Frame|Aspose.Slides Documentation