Convert PowerPoint to PNG in C#
Overview
This article explains how to convert PowerPoint Presentation to PNG format using C#. It covers the following topics.
- Convert PowerPoint to PNG in C#
- Convert PPT to PNG in C#
- Convert PPTX to PNG in C#
- Convert ODP to PNG in C#
- Convert PowerPoint Slide to Image in C#
C# PowerPoint to PNG
For C# sample code to convert PowerPoint to PNG, please see the section below i.e. Convert PowerPoint to PNG. The code can load number of formats like PPT, PPTX and ODP in Presentation object and then save its slide thumbnail to PNG format. The other PowerPoint to Image conversions which are sort of similar like JPG, BMP, TIFF and SVG are discussed in these articles.
About PowerPoint to PNG Conversion
The PNG (Portable Network Graphics) format is not as popular as JPEG (Joint Photographic Experts Group), but it still very popular.
Use case: When you have a complex image and size is not an issue, PNG is a better image format than JPEG.
Tip
You may want to check out Aspose free PowerPoint to PNG Converters: PPTX to PNG and PPT to PNG. They are a live implementation of the process described on this page.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);
}
}
}