Convert PowerPoint to JPG in C#
Overview
This article explains how to convert PowerPoint Presentation to JPG format using C#. It covers the following topics:
- C# Convert PowerPoint to JPG
- C# Convert PPT to JPG
- C# Convert PPTX to JPG
- C# Convert ODP to JPG
- C# Convert PowerPoint Slide to Image
C# PowerPoint to JPG
For C# sample code to convert PowerPoint to JPG, please see the section below i.e. Convert PowerPoint to JPG. The code can load number of formats like PPT, PPTX and ODP in Presentation object and then save its slide thumbnail to JPG format. The other PowerPoint to Image conversions which are sort of similar like PNG, BMP, TIFF and SVG are discussed in these articles.
About PowerPoint to JPG Conversion
With Aspose.Slides .NET API you can convert PowerPoint PPT or PPTX presentation to JPG image. It is also possible to convert PPT/PPTX to BMP, PNG or SVG. With this features it’s easy to implement your own presentation viewer, create the thumbnail for every slide. This may be useful if you want to protect presentation slides from copywriting, demonstrate presentation in read-only mode. Aspose.Slides allows to convert the whole presentation or a certain slide into image formats.
Convert PowerPoint PPT/PPTX to JPG
Here are the steps to convert PPT/PPTX to JPG:
- Create an instance of Presentation class.
- Get the slide object of ISlide type from Presentation.Slides collection.
- Create the thumbnail of each slide and then convert it into JPG. ISlide.GetImage(float scaleX, float scaleY) method is used to get a thumbnail of a slide, it returns Bitmap object as a result. GetImage method has to be called from the needed slide of ISlide type, the scales of the resulting thumbnail are passed into the method.
- After you get the slide thumbnail, call Image.Save(string filename, ImageFormat format) method from the thumbnail object. Pass the resulting file name and the image format into it.
const int imageScale = 1;
using (Presentation pres = new Presentation("PowerPoint-Presentation.ppt"))
{
foreach (ISlide slide in pres.Slides)
{
// Creates a full scale image
using (IImage thumbnail = slide.GetImage(imageScale, imageScale))
{
// Saves the image to disk in JPEG format
string imageFileName = string.Format("Slide_{0}.jpg", slide.SlideNumber);
thumbnail.Save(imageFileName, ImageFormat.Jpeg);
}
}
}
Convert PowerPoint PPT/PPTX to JPG with Customized Dimensions
To change the dimension of the resulting thumbnail and JPG image, you can set the ScaleX and ScaleY values by passing them into the ISlide.GetImage(float scaleX, float scaleY) method:
using (Presentation pres = new Presentation("PowerPoint-Presentation.pptx"))
{
// Defines dimensions
int desiredX = 1200;
int desiredY = 800;
// Gets scaled values of X and Y
float scaleX = (float)(1.0 / pres.SlideSize.Size.Width) * desiredX;
float scaleY = (float)(1.0 / pres.SlideSize.Size.Height) * desiredY;
foreach (ISlide slide in pres.Slides)
{
// Creates a full scale image
using (IImage thumbnail = slide.GetImage(scaleX, scaleY))
{
// Saves the image to disk in JPEG format
string imageFileName = string.Format("Slide_{0}.jpg", slide.SlideNumber);
thumbnail.Save(imageFileName, ImageFormat.Jpeg);
}
}
}
Render Comments when saving Presentation into Image
Aspose.Slides for .NET provides a facility that allows you to render comments in a presentation’s slides when you are converting those slides into images. This C# code demonstrates the operation:
using (Presentation presentation = new Presentation("test.pptx"))
{
IRenderingOptions options = new RenderingOptions
{
SlidesLayoutOptions = new NotesCommentsLayoutingOptions
{
NotesPosition = NotesPositions.BottomTruncated,
CommentsAreaColor = Color.Red,
CommentsAreaWidth = 200,
CommentsPosition = CommentsPositions.Right
}
};
using (IImage image = presentation.Slides[0].GetImage(options))
{
image.Save("OutPresBitmap.png", ImageFormat.Png);
}
System.Diagnostics.Process.Start("OutPresBitmap.png");
}
Tip
Aspose provides a FREE Collage web app. Using this online service, you can merge JPG to JPG or PNG to PNG images, create photo grids, and so on.
Using the same principles described in this article, you can convert images from one format to another. For more information, see these pages: convert image to JPG; convert JPG to image; convert JPG to PNG, convert PNG to JPG; convert PNG to SVG, convert SVG to PNG.
See also
See other options to convert PPT/PPTX into image like: