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# 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. 

todo:image_alt_text

Convert PowerPoint PPT/PPTX to JPG

Here are the steps to convert PPT/PPTX to JPG:

  1. Create an instance of Presentation class.
  2. Get the slide object of ISlide type from Presentation.Slides collection.
  3. Create the thumbnail of each slide and then convert it into JPG. ISlide.GetThumbnail(float scaleX, float scaleY) method is used to get a thumbnail of a slide, it returns Bitmap object as a result. GetThumbnail method has to be called from the needed slide of ISlide type, the scales of the resulting thumbnail are passed into the method.
  4. 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. 
using (Presentation pres = new Presentation("PowerPoint-Presentation.ppt"))
{
	foreach (ISlide sld in pres.Slides)
	{
		// Creates a full scale image
		Bitmap bmp = sld.GetThumbnail(1f, 1f);

		// Saves the image to disk in JPEG format
		bmp.Save(string.Format("Slide_{0}.jpg", sld.SlideNumber), System.Drawing.Imaging.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.GetThumbnail(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 sld in pres.Slides)
	{
		// Creates a full scale image
		Bitmap bmp = sld.GetThumbnail(ScaleX, ScaleY);

		// Saves the image to disk in JPEG format
		bmp.Save(string.Format("Slide_{0}.jpg", sld.SlideNumber), System.Drawing.Imaging.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:

Presentation pres = new Presentation("test.pptx");
Bitmap bmp = new Bitmap(740, 960);

IRenderingOptions opts = new RenderingOptions();
opts.NotesCommentsLayouting.NotesPosition = NotesPositions.BottomTruncated;
opts.NotesCommentsLayouting.CommentsAreaColor = Color.Red;
opts.NotesCommentsLayouting.CommentsAreaWidth = 200;
opts.NotesCommentsLayouting.CommentsPosition = CommentsPositions.Right;

using (Graphics graphics = Graphics.FromImage(bmp))
{
	pres.Slides[0].RenderToGraphics(opts, graphics);
}
bmp.Save("OutPresBitmap.png", ImageFormat.Png);
System.Diagnostics.Process.Start("OutPresBitmap.png");

See also

See other options to convert PPT/PPTX into image like: