GitHub - DevExpress-Examples/presentation-api-get-started: Creates a presentation with slides and saves it to PPTX and PDF. (original) (raw)
This example creates a new presentation, adds three slides, and populates slides with content.
Slide #1
Slide #2
Slide #3
Implementation Details
- 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.SlideMasterscollection.
SlideMaster slideMaster = presentation.SlideMasters[0]; - To create a slide, initialize a
Slideobject and add it to thePresentation.Slidescollection. 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 theGetorGetOrCreatemethod.
Slide slide1 = new Slide(slideMaster.Layouts.Get(SlideLayoutType.Title));
//...
presentation.Slides.Add(slide1); - Layouts add placeholder shapes to slides. Use the
Slide.Shapescollection 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));
Files to Review
Documentation
More Examples
Does This Example Address Your Development Requirements/Objectives?
(you will be redirected to DevExpress.com to submit your response)


