Convert PowerPoint Slides to PNG in C++
Overview
This article explains how to convert presentation slides to PNG images using Aspose.Slides for C++. You can load presentations in formats such as PPT, PPTX, and ODP, render each slide, and save it as a separate PNG image.
The examples below demonstrate rendering at the default scale, increasing the scale, specifying the output dimensions in pixels, and choosing a gradient rendering style.
Convert PowerPoint to PNG
Load a presentation with the Presentation class and access its slides through the Presentation::get_Slide accessor. The example renders every slide with ISlide::GetImage without parameters to create a thumbnail. It then calls IImage::Save with ImageFormat::Png to save each rendered slide as a PNG image.
#include <DOM/ISlide.h>
#include <DOM/ISlideCollection.h>
#include <DOM/Presentation.h>
#include <IImage.h>
#include <ImageFormat.h>
#include <system/string.h>
using namespace Aspose::Slides;
using namespace System;
auto presentation = MakeObject<Presentation>(u"presentation.pptx");
auto slideCount = presentation->get_Slides()->get_Count();
for (auto index = 0; index < slideCount; index++)
{
auto slide = presentation->get_Slide(index);
auto image = slide->GetImage();
image->Save(String::Format(u"slide_{0}.png", index), ImageFormat::Png);
image->Dispose();
}
presentation->Dispose();
Note
The parameterless ISlide::GetImage overload renders at a scale of 0.2. For example, a slide measuring 720 × 540 points produces a 144 × 108 pixel thumbnail. To control the output dimensions, use the overloads with scale factors or an explicit image size shown below.Convert PowerPoint to PNG With Custom Dimensions
Pass horizontal and vertical scale factors to ISlide::GetImage to control the rendered dimensions. In this example, both factors are 2, so a slide measuring 720 × 540 points produces a 1440 × 1080 pixel image. Equal scale factors preserve the slide’s aspect ratio. Each image is saved in PNG format with IImage::Save.
#include <DOM/ISlide.h>
#include <DOM/ISlideCollection.h>
#include <DOM/Presentation.h>
#include <IImage.h>
#include <ImageFormat.h>
#include <system/string.h>
using namespace Aspose::Slides;
using namespace System;
auto presentation = MakeObject<Presentation>(u"presentation.pptx");
auto scaleX = 2.f;
auto scaleY = scaleX;
auto slideCount = presentation->get_Slides()->get_Count();
for (auto index = 0; index < slideCount; index++)
{
auto slide = presentation->get_Slide(index);
auto image = slide->GetImage(scaleX, scaleY);
image->Save(String::Format(u"slide_{0}.png", index), ImageFormat::Png);
image->Dispose();
}
presentation->Dispose();
Convert PowerPoint to PNG With Custom Size
To specify output dimensions in pixels, pass a size to ISlide::GetImage instead of scale factors. This example renders every slide at 960 × 720 pixels and saves the result with IImage::Save. Choose dimensions that match the slide’s aspect ratio to avoid stretching the image.
#include <DOM/ISlide.h>
#include <DOM/ISlideCollection.h>
#include <DOM/Presentation.h>
#include <IImage.h>
#include <ImageFormat.h>
#include <system/string.h>
#include <drawing/size.h>
using namespace Aspose::Slides;
using namespace System;
auto presentation = MakeObject<Presentation>(u"presentation.pptx");
auto imageSize = System::Drawing::Size(960, 720);
auto slideCount = presentation->get_Slides()->get_Count();
for (auto index = 0; index < slideCount; index++)
{
auto slide = presentation->get_Slide(index);
auto image = slide->GetImage(imageSize);
image->Save(String::Format(u"slide_{0}.png", index), ImageFormat::Png);
image->Dispose();
}
presentation->Dispose();
Choose a Gradient Rendering Style
Suppose a slide contains gradient fills, but the transitions in the exported PNG look lighter or otherwise different from what you see in PowerPoint. You can use the SaveOptions::set_GradientStyle method of RenderingOptions to choose how the gradients are rendered.
Download gradient-styles.pptx and place it in the application’s working directory. Its first slide contains two linear gradients: cyan to orange at the top and blue to yellow at the bottom. Each gradient has two stops, at 0% and 100%.
The following example loads this presentation and renders the same first slide in both modes with ISlide::GetImage.
#include <DOM/ISlide.h>
#include <DOM/ISlideCollection.h>
#include <DOM/Presentation.h>
#include <IImage.h>
#include <ImageFormat.h>
#include <system/string.h>
#include <DOM/GradientStyle.h>
#include <Export/RenderingOptions.h>
using namespace Aspose::Slides;
using namespace Aspose::Slides::Export;
using namespace System;
auto presentation = MakeObject<Presentation>(u"gradient-styles.pptx");
auto slide = presentation->get_Slide(0);
auto gradientStyles = { GradientStyle::Default, GradientStyle::PowerPointUI };
for (auto style : gradientStyles)
{
auto options = MakeObject<RenderingOptions>();
options->set_GradientStyle(style);
auto image = slide->GetImage(options, 1.f, 1.f);
auto styleName = style == GradientStyle::Default ? u"Default" : u"PowerPointUI";
image->Save(String::Format(u"gradient-{0}.png", styleName), ImageFormat::Png);
image->Dispose();
}
presentation->Dispose();
The images below show the output from the same slide, with both gradients in each image:
| Default | PowerPointUI |
|---|---|
![]() |
![]() |
In this example, Default produces lighter intermediate colors, while PowerPointUI produces darker intermediate colors. The difference depends on the colors and stops in the gradient.
Choose Default when the standard Aspose.Slides output suits your needs. Try PowerPointUI when your priority is matching the appearance in PowerPoint. Compare both outputs with your intended result; neither mode is universally preferable.
FAQ
How can I export a specific shape, such as a chart or picture, instead of the entire slide?
Aspose.Slides supports generating thumbnails for individual shapes, allowing you to render a shape as a PNG image.
Is parallel conversion supported on a server?
Yes. Use a separate presentation instance for each thread or process; do not share a single instance across threads.
What are the evaluation limitations when exporting to PNG?
Evaluation mode adds a watermark to output images and applies other restrictions until a license is applied.

