Convert PowerPoint to Image using Syncfusion PowerPoint library
10 Sep 202418 minutes to read
Syncfusion PowerPoint library (Presentation) allows you to convert PowerPoint Presentation document to Image within a few lines of code in .NET applications and also it does not require Microsoft PowerPoint application to be installed in the machine. Using this, you can create an input PowerPoint Presentation document from scratch or load an existing PowerPoint Presentation document and then easily convert to Image.
The Syncfusion PowerPoint to Image converter offers high versatility and seamless performance across various .NET platforms, including Windows Forms, WPF, ASP.NET, ASP.NET MVC, ASP.NET Core, Blazor, Xamarin, WinUI, .NET MAUI. Also, in different environments like Azure, AWS, Google Cloud, Linux, and macOS.
Key Features
- Ability to convert entire PowerPoint Presentation document to images.
- Support to convert specific slide of PowerPoint Presentation document to image.
- Set fallback fonts for characters when glyphs are not available.
- Support for font substitution when fonts are not available during PowerPoint to image conversion.
Assemblies and NuGet packages required
Refer to the following links for assemblies required based on platforms to convert the PowerPoint document to image.
To quickly start converting a PowerPoint Presentation to an Image using .NET PowerPoint library, please check out this video:
Convert PowerPoint to Image
The following namespaces are required to compile the code in this topic.
using Syncfusion.Presentation;
using Syncfusion.PresentationRenderer;
using System.IO;
using Syncfusion.Presentation;
using Syncfusion.OfficeChartToImageConverter;
using System.IO;
using Syncfusion.Drawing;
Imports Syncfusion.Presentation
Imports Syncfusion.OfficeChartToImageConverter
Imports Syncfusion.Drawing
Imports System.IO
Convert PowerPoint Presentation to Images
The following code example demonstrates the conversion of an entire Presentation to images.
using (FileStream fileStream = new FileStream("Sample.pptx", FileMode.Open, FileAccess.Read))
{
//Open the existing PowerPoint presentation.
using (IPresentation pptxDoc = Presentation.Open(fileStream))
{
//Initialize the PresentationRenderer to perform image conversion.
pptxDoc.PresentationRenderer = new PresentationRenderer();
//Convert PowerPoint to image as stream.
Stream[] images = pptxDoc.RenderAsImages(ExportImageFormat.Jpeg);
//Saves the images to file system
foreach (Stream stream in images)
{
//Create the output image file stream
using (FileStream fileStreamOutput = File.Create("Output" + Guid.NewGuid().ToString() + ".jpg"))
{
//Copy the converted image stream into created output stream
stream.CopyTo(fileStreamOutput);
}
}
}
}
//Loads the PowerPoint Presentation
IPresentation pptxDoc = Presentation.Open("Sample.pptx");
//Creates instance of ChartToImageConverter
pptxDoc.ChartToImageConverter = new ChartToImageConverter();
//Sets the scaling mode as best
pptxDoc.ChartToImageConverter.ScalingMode = Syncfusion.OfficeChart.ScalingMode.Best;
//Converts entire Presentation to images
Image[] images = pptxDoc.RenderAsImages(Syncfusion.Drawing.ImageType.Metafile);
//Saves the image to file system
foreach (Image image in images)
{
image.Save("ImageOutput" + Guid.NewGuid().ToString()+ ".png");
}
'Loads the PowerPoint Presentation
Dim pptxDoc As IPresentation = Presentation.Open("Sample.pptx")
'Creates instance of ChartToImageConverter
pptxDoc.ChartToImageConverter = New ChartToImageConverter()
'Sets the scaling mode as best
pptxDoc.ChartToImageConverter.ScalingMode = Syncfusion.OfficeChart.ScalingMode.Best
'Converts entire Presentation to images
Dim images As Image() = pptxDoc.RenderAsImages(Syncfusion.Drawing.ImageType.Metafile)
'Saves the image to file system
For Each image As Image In images
image.Save("ImageOutput" + Guid.NewGuid().ToString() + ".png")
Next
You can download a complete working sample from GitHub.
Convert a Slide to Image
TIPS
When converting a slide to image, use ‘Metafile’ format for good image resolution.
The following code example demonstrates how to convert a slide to image.
//Namespaces to perform PPTX to Image conversion
using Syncfusion.Presentation;
using Syncfusion.PresentationRenderer;
using System.IO;
//Open the existing PowerPoint presentation with stream.
using (IPresentation pptxDoc = Presentation.Open(fileStreamInput))
{
//Initialize the PresentationRenderer to perform image conversion.
pptxDoc.PresentationRenderer = new PresentationRenderer();
//Convert PowerPoint slide to image as stream.
using (Stream stream = pptxDoc.Slides[0].ConvertToImage(ExportImageFormat.Jpeg))
{
//Reset the stream position
stream.Position = 0;
//Create the output image file stream
using (FileStream fileStreamOutput = File.Create("Output.jpg"))
{
//Copy the converted image stream into created output stream
stream.CopyTo(fileStreamOutput);
}
}
}
//Namespaces to perform PPTX to Image conversion
using Syncfusion.Presentation;
using Syncfusion.OfficeChartToImageConverter;
using System.IO;
using Syncfusion.Drawing;
//Opens a PowerPoint Presentation file
IPresentation pptxDoc = Presentation.Open(fileName);
//Creates an instance of ChartToImageConverter
pptxDoc.ChartToImageConverter = new ChartToImageConverter();
//Sets the scaling mode as best
pptxDoc.ChartToImageConverter.ScalingMode = Syncfusion.OfficeChart.ScalingMode.Best;
//Converts the first slide into image
Image image = pptxDoc.Slides[0].ConvertToImage(Syncfusion.Drawing.ImageType.Metafile);
//Saves the image as file
image.Save("slide1.png");
//Disposes the image
image.Dispose();
//Closes the Presentation instance
pptxDoc.Close();
'Namespaces to perform PPTX to Image conversion
Imports Syncfusion.Presentation
Imports Syncfusion.OfficeChartToImageConverter
Imports Syncfusion.Drawing
Imports System.IO
'Opens a PowerPoint Presentation file
Dim pptxDoc As IPresentation = Presentation.Open(fileName)
'Creates an instance of ChartToImageConverter
pptxDoc.ChartToImageConverter = New ChartToImageConverter()
'Sets the scaling mode as best
pptxDoc.ChartToImageConverter.ScalingMode = Syncfusion.OfficeChart.ScalingMode.Best
'Converts the first slide into image
Dim image As Image = pptxDoc.Slides(0).ConvertToImage(Syncfusion.Drawing.ImageType.Metafile)
'Saves the image as file
image.Save("slide1.png")
'Disposes the image
image.Dispose()
'Closes the Presentation instance
Presentation_1.Close()
You can download a complete working sample from GitHub.
Supported image formats in .NET Framework
The supported image formats are listed as follows.
- BMP
- EMF
- JPG
- JPEG
- PNG
Image resolution
The following code snippet demonstrates how to convert a PowerPoint slide to image using custom image resolution.
//Loads the PowerPoint presentation
IPresentation pptxDoc = Presentation.Open("Output.pptx");
//Declare variables to hold custom width and height
int customWidth = 1500;
int customHeight = 1000;
//Converts the slide as image and returns the image stream
Stream stream = pptxDoc.Slides[0].ConvertToImage(Syncfusion.Drawing.ImageFormat.Emf);
//Creates a bitmap of specific width and height
Bitmap bitmap = new Bitmap(customWidth, customHeight, PixelFormat.Format32bppPArgb);
//Gets the graphics from image
Graphics graphics = Graphics.FromImage(bitmap);
//Sets the resolution
bitmap.SetResolution(graphics.DpiX, graphics.DpiY);
//Recreates the image in custom size
graphics.DrawImage(System.Drawing.Image.FromStream(stream), new Rectangle(0, 0, bitmap.Width, bitmap.Height));
//Saves the image as bitmap
bitmap.Save("ImageOutput" + Guid.NewGuid().ToString() + ".jpeg");
//Closes the presentation
pptxDoc.Close();
'Loads the PowerPoint presentation
Dim pptxDoc As IPresentation = Presentation.Open("Output.pptx")
'Declare variables to hold custom width and height
Dim customWidth As Integer = 1500
Dim customHeight As Integer = 1000
'Converts the slide as image and returns the image stream
Dim stream As Stream = pptxDoc.Slides(0).ConvertToImage(Syncfusion.Drawing.ImageFormat.Emf)
'Creates a bitmap of specific width and height
Dim bitmap As New Bitmap(customWidth, customHeight, PixelFormat.Format32bppPArgb)
'Gets the graphics from image
Dim imageGraphics As Graphics = Graphics.FromImage(bitmap)
'Sets the resolution
bitmap.SetResolution(imageGraphics.DpiX, imageGraphics.DpiY)
'Recreates the image in custom size
imageGraphics.DrawImage(System.Drawing.Image.FromStream(stream), New Rectangle(0, 0, bitmap.Width, bitmap.Height))
'Saves the image as bitmap
bitmap.Save("ImageOutput" + Guid.NewGuid().ToString() + ".jpeg")
'Closes the presentation
pptxDoc.Close()
You can download a complete working sample from GitHub.
Convert PowerPoint Animations to Images
The .NET PowerPoint Library (Presentation) allows you to convert PowerPoint slides into images based on the sequence of entrance animation effects applied to each element.
For instance, if a slide includes bulleted paragraphs, each having entrance animation effects, the Presentation library converts every bulleted paragraph into a separate image.
NOTE
- Only entrance animation effects are considered for generating separate images. Other animation effects and non-animated elements will be converted into images within the first image itself.
- Converting PowerPoint animations to images is not supported in the UWP platform.
The following code example shows how to convert PowerPoint slides to images based on the sequence of animation effects using the PresentationAnimationConverter API.
//Open a PowerPoint Presentation.
IPresentation pptxDoc = Presentation.Open("Input.pptx");
//Initialize the PresentationAnimationConverter to perform slide to image conversion based on animation order.
using (PresentationAnimationConverter animationConverter = new PresentationAnimationConverter())
{
int i = 0;
foreach (ISlide slide in pptxDoc.Slides)
{
//Convert the PowerPoint slide to a series of images based on entrance animation effects.
Stream[] imageStreams = animationConverter.Convert(slide, ExportImageFormat.Png);
//Save the image stream.
foreach (Stream stream in imageStreams)
{
i++;
//Reset the stream position.
stream.Position = 0;
//Create the output image file stream.
using (FileStream fileStreamOutput = File.Create("Output" + i + ".png"))
{
//Copy the converted image stream into created output stream.
stream.CopyTo(fileStreamOutput);
}
}
}
}
//Open a PowerPoint Presentation.
IPresentation pptxDoc = Presentation.Open("Input.pptx");
//Initialize the PresentationAnimationConverter to perform slide to image conversion based on animation order.
using (PresentationAnimationConverter animationConverter = new PresentationAnimationConverter())
{
int i = 0;
foreach (ISlide slide in pptxDoc.Slides)
{
//Convert the PowerPoint slide to a series of images based on entrance animation effects.
Stream[] imageStreams = animationConverter.Convert(slide, Syncfusion.Drawing.ImageFormat.Png);
//Save the image stream.
foreach (Stream stream in imageStreams)
{
i++;
//Reset the stream position.
stream.Position = 0;
//Create the output image file stream.
using (FileStream fileStreamOutput = File.Create("Output" + i + ".png"))
{
//Copy the converted image stream into created output stream.
stream.CopyTo(fileStreamOutput);
}
}
}
}
' Open a PowerPoint Presentation.
Dim pptxDoc As IPresentation = Presentation.Open("Input.pptx")
' Initialize the PresentationAnimationConverter to perform slide to image conversion based on animation order.
Using animationConverter As New PresentationAnimationConverter()
Dim i As Integer = 0
For Each slide As ISlide In pptxDoc.Slides
' Convert the PowerPoint slide to a series of images based on entrance animation effects.
Dim imageStreams As Stream() = animationConverter.Convert(slide, Syncfusion.Drawing.ImageFormat.Png)
' Save the image stream.
For Each stream As Stream In imageStreams
i += 1
' Reset the stream position.
stream.Position = 0
' Create the output image file stream.
Using fileStreamOutput As FileStream = File.Create("Output" & i & ".png")
' Copy the converted image stream into created output stream.
stream.CopyTo(fileStreamOutput)
End Using
Next
Next
End Using
You can download a complete working sample from GitHub.
TIPS
With this, you can showcase the converted images as a slideshow in your custom PowerPoint Viewer.
UWP
PowerPoint slides can be converted to images in UWP platform by using Essential Presentation library. For further information, click here.
Font Substitution
When a font used in a PowerPoint presentation is unavailable in the environment where it is converted to image, then the library substitutes the ‘Microsoft Sans Serif’ as a default font for text rendering. This leads to a difference in text layouts of PowerPoint presentation and the converted image.
To avoid this, the Essential Presentation library allows you to set an alternate font for the missing font used in the PowerPoint presentation. For further information, click here.
Fallback fonts
During PowerPoint to Image conversions, if a glyph of the input text is unavailable in the specified font, the text will not be rendered properly. To address this, the Syncfusion PowerPoint (Presentation) library allows users to specify fallback fonts. When a glyph is missing, the library will use one of the fallback fonts to render the text correctly in the output image. For further information, click here.