a blog for those who code

Wednesday, 9 September 2015

Convert each slide of Powerpoint Presentation to Image in C#

In this post we are going to discuss about converting each slide of powerpoint presentation to image in C#. There might be scenario where you want to convert whole or part of your powerpoint presentation to a group of images.

Converting each slide of powerpoint presentation to image is very simple, you just need to add references of  Microsoft.Office.Interop.PowerPoint and Microsoft.Office.Core in your application.

The full code of converting each slide of Powerpoint Presentation to Image in C# is shown below

using Microsoft.Office.Interop.PowerPoint;
using Microsoft.Office.Core;

namespace ConsoleApplication1
{
 class Program
 {
  static void Main(string[] args)
  {
   Application pptApplication = new Application();
   pptApplication.Visible = MsoTriState.msoTrue;
   Presentation ppt = pptApplication.Presentations.Open(@"Your_PowerPointFileLocation", MsoTriState.msoFalse, MsoTriState.msoFalse, MsoTriState.msoFalse);

   var count = 0;
   foreach(Slide slide in ppt.Slides)
   {
    slide.Export(@"Your_Image_Location\slide" + count + ".png", "png", 320, 240);
    count++;
   }
  }
 }
}

In our code at first we have created an object of Application Class (interface Microsoft.Office.Interop.PowerPoint.Application). Then using the application object we have open our presentations using function pptApplication.Presentations.Open(). Now we have Presentation object, from which we can extract each slides and export it to the image using function slide.Export().

Lets say you have a powerpoint presentation of 3 slides like below.


The above code will give you 3 images (slide0, slide1 and slide2) like below.


Please Like and Share CodingDefined.com Blog, if you find it interesting and helpful.

No comments:

Post a Comment

Contact Us

Name

Email *

Message *

Sponsers

Best Hosting Plans

CC License