John Dyer

Technology and web development in curly bracket languages {Javascript, C#, ActionScript}

Tips for Exporting slides from Powerpoint in C#

by John Dyer 31. August 2005 12:29

I recently needed to export slides from powerpoint as images to use in another application. I ran into two issues along the way that I thought I'd share in hopes that it will speed someone else's development time.

Office Versions
Some of the end users had Office XP (2002) and some had Office 2003. The Office API is different for for 2002 and 2003 so I had to use the provider pattern for the two versions. The export slide functionality looks like this:

Office 2002

using Microsoft.Office.Core;
using PowerPoint;
ApplicationClass pptApplication = new ApplicationClass();
Presentation pptPresentation = pptApplication.Presentations.Open("myfile.ppt", MsoTriState.msoFalse, MsoTriState.msoFalse, MsoTriState.msoFalse);
pptPresentation.Slides.Item(1).Export("slide.jpg", "jpg", 320, 240);

Office 2003

using Microsoft.Office.Core;
using Microsoft.Office.Interop.PowerPoint;
ApplicationClass pptApplication = new ApplicationClass();
Presentation pptPresentation = pptApplication.Presentations.Open("myfile.ppt", MsoTriState.msoFalse,
MsoTriState.msoFalse, MsoTriState.msoFalse);

pptPresentation.Slides.Item[1].Export("slide.jpg", "jpg", 320, 240);

The main differences are (1) the namespaces have changed and (2) the Slides collection is accessed as a method in 2002 and as an indexed property in 2003. Once the code differences are determined, I created an abstract PowerpointExporter class and a class for each office version I had to support.

Image Output Quality
I found that the above code produced fairly low quality JPG images. There was high degree of artifacting around text, the text wasn't antialiased and the images our artists used as background didn't look very good. Since there is no way to tell Powerpoint what JPG compression to use, I changed the code to output as lossless PNG files and I changed the output to the size of the background images in the original Powerpoint. For Office 2003, the code looked like this:

pptPresentation.Slides.Item[1].Export("slide.png", "PNG", 1024, 768);

After the extraction, I resized and compressed the PNGs into the JPGs I need and the slides look great.

Comments

8/3/2008 3:06:56 AM # lamia lamia Tunisia | Reply

Hell,
I'd like to  know how can I  export slide from PowerPoint to .Tiff file with Microsoft office 2007.
Think you

Add comment


(Will show your Gravatar icon)

  Country flag

biuquote
  • Comment
  • Preview
Loading



Web Statistics