Convert PPT/PPTX to PNG in C#

It is not uncommon that we may need to convert a PowerPoint file to images or a PDF file in our work. In my previous post, I have introduced how to export PPT/PPTX files as PDFs. This article will introduce how we can convert a PPT/PPTX file into PNGs by using Spire.Presentation in C#.

Here come the code snippets:


using Spire.Presentation;
using System.Drawing;

namespace Conversion
{
    class Program
    {
        static void Main(string[] args)
        {
            //Initialize an instance of Presentation class
            Presentation presentation = new Presentation();

            //Load a PowerPoint document
            presentation.LoadFromFile("Template.pptx");

            //Traverse each slide in PowerPoint and save as png image
            for (int i = 0; i < presentation.Slides.Count; i++)
            {
                Image image = presentation.Slides[i].SaveAsImage();
                String fileName = String.Format("Result-{0}.png", i);
                image.Save(fileName);
            }
        }
    }
}

Output

2017-05-08_152546

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s