Convert Powerpoint PPT or PPTX to JPG in C#
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 type.
- Get the slide object of ISlide type from Presentation.Slides collection.
- 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.
- 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)
{
// Create a full scale image
Bitmap bmp = sld.GetThumbnail(1f, 1f);
// Save 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 for it. To do that, pass ScaleX and ScaleY values into ISlide.GetThumbnail(float scaleX, float scaleY) method:
using (Presentation pres = new Presentation("PowerPoint-Presentation.pptx"))
{
// Define dimensions
int desiredX = 1200;
int desiredY = 800;
// Get 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)
{
// Create a full scale image
Bitmap bmp = sld.GetThumbnail(ScaleX, ScaleY);
// Save 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 to render comments of presentations or slide when converting those into images. An example is given below that shows how to render comments of presentation into an image.
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");
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.See also
See other options to convert PPT/PPTX into image, like: