How to export PowerPoint files for developers using C#

Converting PowerPoint files to something else is a common task in software development that involve Office documents including .ppt, .doc, .pptx, .xls, etc. Fortunately we can use .NET and C# in conjunction with Interop DLL libraries to perform this task with a simple steps and without incurring in 3rd party libraries to do the job.

This code snippet in C# may be helpful for developers using Visual Studio Express or any other IDE trying to export PowerPoint presentations to HTML or even image format as output. You can also Save As your files programmatically to PDF or other output formats.

Application pptApplication = new Application();
Presentation pptPresentation = pptApplication.Presentations.Open("c:\\temp\\test.pptx", MsoTriState.msoFalse,MsoTriState.msoFalse, MsoTriState.msoFalse);
pptPresentation.Slides[1].Export("c:\\temp\\slide.png", "png", 320, 240);
pptPresentation.Slides[1].PublishSlides("c:\\temp\\slide\\", true, true);
pptPresentation.ExportAsFixedFormat("c:\\temp\\slide\\example.pdf", PpFixedFormatType.ppFixedFormatTypePDF,
PpFixedFormatIntent.ppFixedFormatIntentScreen);
pptPresentation.SaveAs("c:\\temp\\slide\\example.html", PpSaveAsFileType.ppSaveAsHTMLDual);
pptPresentation.SaveAs("c:\\temp\\slide\\exampledual.html", PpSaveAsFileType.ppSaveAsHTMLDual);

Aside of exporting to html and PNG you can also export to other formats including JPG, BMP.

You can change properties like PpFixedFormatIntent, PpFixedFormatType as well as other output properties that let you customize the way files are exported.

The following methods can be helpful as well, depending on the task that you want to perform:

  • Export
  • ExportAsFixedFormat
  • PublishSlides
  • SaveAs
Notice that some of these methods belong to slides class while others belong to presentation class.

ExportAsFixedFormat let you export your presentations to XPS or PDF format. You can learn more about these methods in MSDN library.