Home > Articles > .Net Framework Articles > How to convert PowerPoint presentation slide to image in C#

How to convert PowerPoint presentation slide to image in C#

by Jane Smith   on Jan 11, 2018   Category: .Net Framework  | Level: Beginner  |  Views: 53    |  Points: 100   
Like this article? Bookmark and Share:
C# examples of how to convert the PowerPoint presentation slides to image file format (PNG/BMP/JPEG/TIFF/EMF/SVG)

In this article, I will explain the steps you can convert the PowerPoint presentation slides to image file format (PNG/BMP/JPEG/TIFF/EMF/SVG). With the help of Spire.Presentation, we can not only save the whole PowerPoint presentation slides as image, but also convert the single element on the presentation slides, such as chart, table and shapes to image.

As widely known that there are two kinds of graphics for the image format, Bitmap images and vector images. Here I will show you how to convert the presentation slides to bitmap images in PNG, BMP, JPEG, TIFF and vector images in EMF, SVG separately.

Convert the presentation slides to bitmap images (BMP, Jpeg, Png, Tiff, WMF)

1.       By calling the method of ISlide.SaveAsImage() offered by Spire.Presentation, we can save the special presentation slides to the common used bitmap images, includes BMP, Jpeg, Png, Tiff, and WMF with the original size. We use .Png for the example.

Presentation presentation = new Presentation();

presentation.LoadFromFile("Sample.pptx", FileFormat.Pptx2013);

for (int i = 0; i < presentation.Slides.Count; i++)

{

    Image image = presentation.Slides[i].SaveAsImage();

    String fileName = String.Format("Image{0}.Png", i);

    image.Save(fileName, System.Drawing.Imaging.ImageFormat.Png);

}


2.      
TIFF image could combine multiple images together and we could also call to use the presentation.SaveToFile() method to save the PowerPoint presentation slides as TIFF image format.

Presentation presentation = new Presentation();

presentation.LoadFromFile("Sample.pptx", FileFormat.Pptx2013);

presentation.SaveToFile("Result.tiff", FileFormat.Tiff);

3.       We can also use ISlide.SaveAsImage(int width, int height) method to save a particular presentation slide as image with specified size.

Presentation presentation = new Presentation();

presentation.LoadFromFile("Sample.pptx", FileFormat.Pptx2013);

Image img = presentation.Slides[0].SaveAsImage(600, 400);

img.Save("SpecialSize.png", System.Drawing.Imaging.ImageFormat.Png);

Convert the presentation slides to Vector images(EMF, SVG)

The following steps will show you how to save the presentation slides to EMF and SVG separately.

1.       Convert the presentation slides to EMF by using the method of ISlide.SaveAsEMF(string filePath) directly.

Presentation presentation = new Presentation();

presentation.LoadFromFile("sample.pptx");

//Traverse every presentation slides and save them to EMF image

for (int i = 0; i < presentation.Slides.Count; i++)

{

    String fileName = String.Format("PPTtoEmf{0}.emf", i);

    presentation.Slides[i].SaveAsEMF(fileName);

}

2.       Convert the presentation slides to SVG by using the method of Presentation.SaveToSVG() directly:

Presentation presentation = new Presentation();

presentation.LoadFromFile("Sample.pptx",FileFormat.Pptx2013);

//Convert PowerPoint document to byte array and store in a Queue object.

Queue<byte[]> svgBytes = presentation.SaveToSVG();

//Dequeue the data in the Queue object and write to the stream.

int len = svgBytes.Count;

for (int i = 0; i < len; i++)

{

    FileStream fs = new FileStream(string.Format("PPTtoSVG{0}.svg", i), FileMode.Create);

    byte[] bytes = svgBytes.Dequeue();

    fs.Write(bytes, 0, bytes.Length);

    presentation.Dispose();

} 

The table, chart and shape on the presentation slides are the single element on the presentation slides and all of them are defined as shapes. Here I will show you how to only convert the table, chart and shapes on the presentation slides to images by calling ShapeList.SaveAsImage(int shapeIndex) method to save table, chart and shape as image.

Presentation presentation = new Presentation();

presentation.LoadFromFile("Sample.pptx", FileFormat.Pptx2013);

for (int i = 0; i < presentation.Slides[0].Shapes.Count; i++)

{

    Image image = presentation.Slides[0].Shapes.SaveAsImage(i);

    image.Save(String.Format("ShapeasImage{0}.png", i), System.Drawing.Imaging.ImageFormat.Png);

}

Thanks for reading and hopes it helps.

 

 



Like this article? Bookmark and Share:

Most viewed Articles

User Comments


No response found, be the first to review this article.

Submit feedback about this article

Please sign in to post feedback

Latest Posts