Click here to Skip to main content
Click here to Skip to main content

A Simple Library to Generate PowerPoint Presentations

, 5 Jun 2014 CPOL
Rate this:
Please Sign up or sign in to vote.
Generate a PowerPoint presentation, consisting of slides with a title and an image, without requiring Microsoft Office

Introduction

I needed a simple way to generate a PowerPoint presentation, consisting of slides with a title and an image. Most approaches use the Microsoft Office interop for this, but unfortunately, the application couldn't rely on Microsoft Office to be installed. However, you can download and use the OpenXML SDK 2.5 for Microsoft Office to create a PowerPoint for you, and I've done just that.

Background

This tip basically provides you with a simple library to generate PowerPoint slides consisting of a slide title and image. I cannot take credit for most of the code, however, as I've taken it from existing examples. Specifically, I've reused the code in the below articles, and re-organized them into a library for easy use:

Using the Code

In order to use the code, either include the PowerPointGenerator project, or add a reference to:

  • DocumentFormat.OpenXml.dll
  • PowerPointGenerator.dll

Next, you can use the code as follows:

var powerPointGenerator = new PowerPointFactory
(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "JessicaAlba.pptx"));
var imageFilePaths = Directory.GetFiles(@"..\..\..\Alba", "*.jpg").ToList();
powerPointGenerator.CreateTitleAndImageSlides(imageFilePaths);

Here, I assume that the generated PowerPoint is saved to the output folder as JessicaAlba.pptx, and it consists of one slide per JPG image in the Alba folder (part of the solution). As I do not specify the titles explicitly, the filename is used as the slide title, but you can also supply a list of titles (one for each slide).

powerPointGenerator.CreateTitleAndImageSlides
(imageFilePaths, new List<string> { "title 1", "title 2" });

Points of Interest

The OpenXML SDK also contains a tool, OpenXmlSdkTool (in c:\Program Files (x86)\Open XML SDK\V2.5\tool\OpenXmlSdkTool.exe), which converts an existing PowerPoint presentation to a class that can recreate this presentation for you (including the styles, masters, etc.). Pretty amazing, and I've used it to generate the Template.cs class in this project.

History

  • 2014-06-04 Article written and first version of the code
  • 2014-06-06 Source code couldn't be downloaded - fixed

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Erik Vullings
Architect
Netherlands Netherlands
No Biography provided
Follow on   Twitter   LinkedIn

Comments and Discussions

 
QuestionCannot download your sample project Pinmemberfredatcodeproject6-Jun-14 6:52 
AnswerRe: Cannot download your sample project PinmemberErik Vullings6-Jun-14 13:35 
GeneralRe: Cannot download your sample project Pinmemberfredatcodeproject7-Jun-14 12:52 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.150331.1 | Last Updated 5 Jun 2014
Article Copyright 2014 by Erik Vullings
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid