MS PowerPoint is a powerful tool that offers a rich stack of multimedia options to make your presentation even more professional and attractive. PPT/PPTX files are easy to store and convert to any other popular file format. However, in many scenarios, you need to convert your presentation slides to any other image format such as PNG. Interestingly, you may achieve this PPT to PNG Image conversion using this C# PowerPoint library. Therefore, let’s learn how to convert PPT to PNG using C# programmatically.
We will cover the following points:
- C# PowerPoint to Image Rendering Library - Installation
- Convert PPT to PNG Image using C#
- PPTX to PNG with Custom Size in C#
- PowerPoint to PNG with Custom Dimension in C#
C# PowerPoint to Image Rendering Library - Installation
The installation procedure of this API is developer-friendly. However, you can either download this .NET PowerPoint library or install it by running the following commands in the NuGet package manager.
Install-Package Aspose.Slides.NET
Convert PPT to PNG Image using C#
This library provides rich methods to manipulate, create and convert PPT/PPTX files to other file formats programmatically.
You may follow the following steps and the code snippet to convert PPT to PNG:
- Load the source PPT file by initializing an instance of the Presentation class.
- Access the property Presentation.Slides which returns a list of all slides that are defined in the presentation.
- Assign the slides to the ISlide interface.
- Invoke the GetThumbnail method to get the thumbnail for every slide and call the Save method to save the slides in PNG format.
The following code snippet shows how to convert a PPT PPTX Presentation to a PNG image in C#:
// Load the source PPT file by initializing an instance of the Presentation class | |
using (Presentation pres = new Presentation("sample.ppt")) | |
{ | |
// Acces the property Presentation.Slides that returns a list of all slides that are defined in the presentation. | |
for (var index = 0; index < pres.Slides.Count; index++) | |
{ | |
// Assign the slides to the ISlide interface | |
ISlide slide = pres.Slides[index]; | |
// Invoke the GetThumbnail method to get the thumbnail for every slide and call the Save method to save the slides in PNG format. | |
slide.GetThumbnail().Save($"slide_{index}.png", ImageFormat.Png); | |
} | |
} |
You may see the output in the image below:
PPTX to PNG with Custom Size in C#
In this section, we will see how can we configure the API call to customize the size of the output PNG file.
Following are the steps and the code snippet:
- Instantiate an instance of the Presentation class and load the source PPT file.
- Set the custom dimensions by defining the scaleX, and scaleY values.
- Loop through all the Slides.
- Get the thumbnail with the custom dimensions and Save the slides in PNG format.
The sample code below demonstrates how to render PPTX to PNG image in C#:
// Instantiate an instance of the Presentation class and load the source PPT file | |
using (Presentation pres = new Presentation("sample.ppt")) | |
{ | |
// set the custom dimensions by defining the scaleX, scaleY values | |
float scaleX = 2f; | |
float scaleY = 2f; | |
// Loop trhough all the Slides | |
for (var index = 0; index < pres.Slides.Count; index++) | |
{ | |
ISlide slide = pres.Slides[index]; | |
// Get the thumbnail with the custom dimensions and Save the slides in PNG format. | |
slide.GetThumbnail(scaleX, scaleY).Save($"slide_{index}.png", ImageFormat.Png); | |
} | |
} |
You may see the output in the screenshot below:
PowerPoint to PNG with Custom Dimension in C#
So far, we have learned how to convert PPT to PNG using C# programmatically. Therefore, let’s see how can we customize the dimensions of the PNG file using this C# PowerPoint library.
The steps and the code snippets are mentioned below:
- Initialize an object of the Presentation class and load the source PPT file.
- Set the custom size of the PNG files by initializing the value of the Size constructor.
- Loop through all the Slides.
- Invoke the GetThumbnail method to obtain the thumbnail of custom size and Save the slides in PNG format.
The following code sample demonstrates how to export a PowerPoint PPTX presentation to PNG image in C#:
// Initialize an object of the Presentation class and load the source PPT file | |
using (Presentation pres = new Presentation("sample.ppt")) | |
{ | |
// set the custom size of the PNG files by initializing the value of the Size constructor | |
Size size = new Size(960, 720); | |
// Loop through all the Slides | |
for (var index = 0; index < pres.Slides.Count; index++) | |
{ | |
ISlide slide = pres.Slides[index]; | |
// Invoke the GetThumbnail method to obtain the thumbnail of custom size and Save the slides in PNG format | |
slide.GetThumbnail(size).Save($"slide_{index}.png", ImageFormat.Png); | |
} | |
} |
Get a Free License
You may get a free temporary license to try the API without evaluation limitations.
Summing up
This brings us to the end of this blog post. We have gone through how to convert PPT PPTX to PNG image using C# programmatically. In addition, we also have covered some other prominent methods of this C# PowerPoint library. However, you may visit the documentation to learn other methods. Finally, please stay in touch with conholdate.com for regular updates.
Ask a question
You can let us know about your questions or queries on our forum.
FAQs
Can we convert PPT to image?
Yes, you can install this C# PowerPoint library to convert PPT to image file formats programmatically.
How do I convert a PPT to a PNG?
Follow this link to learn how to automate the PPT/PPTX to PNG conversion in a C# application.