This example creates a new presentation, adds three slides, and populates slides with content.
Important
You need a license for the DevExpress Office File API Subscription or DevExpress Universal Subscription to use our Office File API library in production code. For pricing information, refer to the following webpage: DevExpress Subscriptions.
-
Use the
Presentation()
parameterless constructor to create a new presentation.Presentation presentation = new Presentation();
-
A newly created presentation contains a single default slide master. The Slide Master is a top-level template slide that you can use as a base for other slides. Slide masters store content, layouts and settings that you can share among derived slides. The default slide master goes first in the
Presentation.SlideMasters
collection.SlideMaster slideMaster = presentation.SlideMasters[0];
-
To create a slide, initialize a
Slide
object and add it to thePresentation.Slides
collection. For each slide, specify the layout type as a constructor parameter. In this example, slides use predefined layouts stored in the slide master. To obtain a layout fromSlideMaster.Layouts
, call theGet
orGetOrCreate
method.Slide slide1 = new Slide(slideMaster.Layouts.Get(SlideLayoutType.Title)); //... presentation.Slides.Add(slide1);
-
Layouts add placeholder shapes to slides. Use the
Slide.Shapes
collection to access placeholder shapes and populate them with content.foreach (Shape shape in slide1.Shapes) { if (shape.PlaceholderSettings.Type is PlaceholderType.CenteredTitle) { shape.TextArea = new TextArea("Daily Testing Status Report"); } if (shape.PlaceholderSettings.Type is PlaceholderType.Subtitle) { shape.TextArea = new TextArea($"{DateTime.Now: dddd, MMMM d, yyyy}"); } }
-
You can save the resulting presentation to a PPTX file and export it to a PDF file:
FileStream outputStream = new FileStream(@"..\..\..\data\my-presentation.pptx", FileMode.Create); presentation.SaveDocument(outputStream); outputStream.Dispose(); presentation.ExportToPdf(new FileStream(@"..\..\..\data\exported-document.pdf", FileMode.Create));
(you will be redirected to DevExpress.com to submit your response)