Convert PowerPoint Slides to PNG in .NET
Overview
This article explains how to convert PowerPoint presentations to PNG images using Aspose.Slides. It shows how to load presentation files in formats such as PPT, PPTX, and ODP, render slides as images, and save the results in PNG format.
The article also demonstrates how to customize the generated PNG images by setting scale values or specifying the desired width and height.
Convert PowerPoint to PNG
Go through these steps:
- Instantiate the Presentation class.
- Get the slide object from the Presentation.Slides collection under the ISlide interface.
- Use a ISlide.GetImage method to get the thumbnail for each slide.
- Use the IPresentation.Save(String, SaveFormat, ISaveOptions method to save the slide thumbnail to the PNG format.
This C# code shows you how to convert a PowerPoint presentation to PNG. Presentation object can load PPT, PPTX, ODP etc, then each slide in presentation object is converted to PNG format or other images format.
using (Presentation pres = new Presentation("pres.pptx"))
{
for (var index = 0; index < pres.Slides.Count; index++)
{
ISlide slide = pres.Slides[index];
using (IImage image = slide.GetImage())
{
image.Save($"slide_{index}.png", ImageFormat.Png);
}
}
}
Convert PowerPoint to PNG With Custom Dimensions
If you want to obtain PNG files around a certain scale, you can set the values for desiredX and desiredY, which determine the dimensions of the resulting thumbnail.
This code in C# demonstrates the described operation:
using (Presentation pres = new Presentation("pres.pptx"))
{
float scaleX = 2f;
float scaleY = 2f;
for (var index = 0; index < pres.Slides.Count; index++)
{
ISlide slide = pres.Slides[index];
using (IImage image = slide.GetImage(scaleX, scaleY))
{
image.Save($"slide_{index}.png", ImageFormat.Png);
}
}
}
Convert PowerPoint to PNG With Custom Size
If you want to obtain PNG files around a certain size, you can pass your preferred width and height arguments for imageSize.
This code shows you how to convert a PowerPoint to PNG while specifying the size for the images:
using (Presentation pres = new Presentation("pres.pptx"))
{
Size size = new Size(960, 720);
for (var index = 0; index < pres.Slides.Count; index++)
{
ISlide slide = pres.Slides[index];
using (IImage image = slide.GetImage(size))
{
image.Save($"slide_{index}.png", ImageFormat.Png);
}
}
}
FAQ
How can I export only a specific shape (e.g., chart or picture) rather than the whole slide?
Aspose.Slides supports generating thumbnails for individual shapes; you can render a shape to a PNG image.
Is parallel conversion supported on a server?
Yes, but don’t share a single presentation instance across threads. Use a separate instance per thread or process.
What are the trial-version limitations when exporting to PNG?
The evaluation mode adds a watermark to output images and enforces other restrictions until a license is applied.