Create Your First Presentation with DevExpress Presentation API Library
- 8 minutes to read
Important
The DevExpress Presentation API Library is currently available as a Community Technology Preview (CTP). Note that we do not recommend that you integrate pre-release libraries into mission-critical software applications. You can try the library and share your feedback so that we can make necessary adjustments before the official release. To start a conversation, submit a ticket via the DevExpress Support Center — we’d love to hear from you.
Important
You need a license for the DevExpress Office File API Subscription or DevExpress Universal Subscription to use this library in production code.
Follow this tutorial to get started with the DevExpress Presentation API for .NET and .NET Framework.
Create a .NET Application
Start Visual Studio and create a new Console Application project.
Install the DevExpress.Docs.Presentation package.
For more information on how to set up the DevExpress NuGet package feed, refer to the following help section: Choose Between Offline and Online DevExpress NuGet Feeds.
Create a .NET Framework Application
Start Visual Studio and create a new Console Application (.NET Framework) project.
Install the DevExpress.Docs.Presentation package or add references to the following libraries (if you used the DevExpress Unified Component Installer to install our products):
- DevExpress.Docs.Presentation.v25.1.dll
- DevExpress.Data.v25.1.dll
- DevExpress.Drawing.v25.1.dll
- DevExpress.Printing.v25.1.Core.dll
- DevExpress.Office.v25.1.Core.dll
- DevExpress.Docs.Core.v25.1.dll
- DevExpress.Pdf.v25.1.Core.dll
Create a Presentation
Open the Program.cs (Module1.vb) file. Paste the code below in the Main
method of the Program
class (Main
procedure of the Module1
module in Visual Basic) to create an empty presentation. A newly created presentation contains a single title slide:
using DevExpress.Docs.Presentation;
namespace DxPresentationGetStarted;
public class Program {
public static void Main(string[] _) {
// Creates a presentation with a single empty slide.
Presentation presentation = new Presentation();
}
}
Configure the Slide Master
A new presentation contains a single default slide master - a layout and appearance settings storage that helps you create consistent slides. To access the default slide master, read the first element in the presentation’s SlideMasters collection.
Set the slide master’s Background property to specify the background fill for all descendant slides.
SlideMaster slideMaster = presentation.SlideMasters[0];
slideMaster.Background = new CustomSlideBackground(new SolidFill(Color.FromArgb(194, 228, 249)));
For more information about slide masters, refer to the following help topic: Configure Slide Masters and Layouts.
Add Slides
In this section, you will add three slides to the presentation.
Before you add the first slide, you have to remove the default slide:
For more information about basic operations with slides, refer to the following help topic: Manage Slides.
Add Slide #1
The first slide contains the presentation name.
Use the slide master’s Title Layout to create a new Slide.
You can now access content placeholders - shapes with given coordinates available through the Shapes collection. Specify each placeholder’s content depending on its type.
Add the resulting slide to the presentation’s
Slides
collection.
Slide slide1 = new Slide(slideMaster.Layouts.Get(SlideLayoutType.Title));
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}");
}
}
presentation.Slides.Add(slide1);
Add Slide #2
The second slide displays a caption and a bullet list.
Use the slide master’s Object Layout to create a Slide.
Populate slide placeholders with content as you did in the previous step.
Add the resulting slide to the presentation’s
Slides
collection.
Slide slide2 = new Slide(slideMaster.Layouts.GetOrCreate(SlideLayoutType.Object));
foreach (Shape shape in slide2.Shapes) {
if (shape.PlaceholderSettings.Type is PlaceholderType.Title) {
shape.TextArea = new TextArea("Today’s Highlights");
}
if (shape.PlaceholderSettings.Type is PlaceholderType.Object) {
TextArea textArea = new TextArea();
textArea.Paragraphs.Clear();
textArea.Paragraphs.Add(new TextParagraph("5 successful builds"));
textArea.Paragraphs.Add(new TextParagraph("2 failed builds"));
textArea.Paragraphs.Add(new TextParagraph("12 new bugs reported"));
textArea.Paragraphs.Add(new TextParagraph("3 deployments"));
textArea.Paragraphs.Add(new TextParagraph("1 rollback"));
shape.TextArea = textArea;
}
}
presentation.Slides.Add(slide2);
Add Slide #3
The third slide displays a caption and an image.
Use the slide master’s Object Layout to create a Slide.
Populate slide placeholders with content as you did in the previous step. To show an image within a shape, assign a PictureFill instance to the shape’s Fill property. Use a DXImage as an image source.
Add the resulting slide to the presentation’s
Slides
collection.
Slide slide3 = new Slide(slideMaster.Layouts.GetOrCreate(SlideLayoutType.Object));
foreach (Shape shape in slide3.Shapes) {
if (shape.PlaceholderSettings.Type is PlaceholderType.Title) {
shape.TextArea = new TextArea("Build Status");
}
if (shape.PlaceholderSettings.Type is PlaceholderType.Object) {
shape.TextArea = new TextArea(" ");
string imagePath = @"..\..\..\data\table.png";
Stream stream = new FileStream(imagePath, FileMode.Open, FileAccess.Read);
PictureFill fill = new PictureFill(DXImage.FromStream(stream));
fill.Stretch = true;
shape.Fill = fill;
}
}
presentation.Slides.Add(slide3);
Add Footers
The Presentation API library uses the HeaderFooterManager to manage slide headers and footers.
Access the HeaderFooterManager
object and call its AddSlideNumberPlaceholder and AddFooterPlaceholder methods to display slide numbers and the same footer text on all slides.
presentation.HeaderFooterManager.AddSlideNumberPlaceholder(presentation.Slides);
presentation.HeaderFooterManager.AddFooterPlaceholder(presentation.Slides, "ProductXCompany");
Save to PPTX
Call the SaveDocument method to save the resulting presentation to a PPTX file:
FileStream outputStream = new FileStream(@"..\..\..\data\my-presentation.pptx", FileMode.Create);
presentation.SaveDocument(outputStream);
outputStream.Dispose();
Export the Presentation
Call the ExportToPdf method to export the presentation to PDF:
presentation.ExportToPdf(new FileStream(@"..\..\..\data\exported-document.pdf", FileMode.Create));
Results
The resulting presentation appears as follows:
- Slide #1
- Slide #2
- Slide #3
The following code snippet contains the complete code:
using DevExpress.Docs.Presentation;
using DevExpress.Drawing;
using System.Drawing;
namespace DxPresentationGetStarted;
public class Program {
public static void Main(string[] _) {
Presentation presentation = new Presentation();
presentation.Slides.Clear();
SlideMaster slideMaster = presentation.SlideMasters[0];
slideMaster.Background = new CustomSlideBackground(new SolidFill(Color.FromArgb(194, 228, 249)));
Slide slide1 = new Slide(slideMaster.Layouts.Get(SlideLayoutType.Title));
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}");
}
}
presentation.Slides.Add(slide1);
Slide slide2 = new Slide(slideMaster.Layouts.GetOrCreate(SlideLayoutType.Object));
foreach (Shape shape in slide2.Shapes) {
if (shape.PlaceholderSettings.Type is PlaceholderType.Title) {
shape.TextArea = new TextArea("Today’s Highlights");
}
if (shape.PlaceholderSettings.Type is PlaceholderType.Object) {
TextArea textArea = new TextArea();
textArea.Paragraphs.Clear();
textArea.Paragraphs.Add(new TextParagraph("5 successful builds"));
textArea.Paragraphs.Add(new TextParagraph("2 failed builds"));
textArea.Paragraphs.Add(new TextParagraph("12 new bugs reported"));
textArea.Paragraphs.Add(new TextParagraph("3 deployments"));
textArea.Paragraphs.Add(new TextParagraph("1 rollback"));
shape.TextArea = textArea;
}
}
presentation.Slides.Add(slide2);
Slide slide3 = new Slide(slideMaster.Layouts.GetOrCreate(SlideLayoutType.Object));
foreach (Shape shape in slide3.Shapes) {
if (shape.PlaceholderSettings.Type is PlaceholderType.Title) {
shape.TextArea = new TextArea("Build Status");
}
if (shape.PlaceholderSettings.Type is PlaceholderType.Object) {
shape.TextArea = new TextArea(" ");
string imagePath = @"..\..\..\data\table.png";
Stream stream = new FileStream(imagePath, FileMode.Open, FileAccess.Read);
PictureFill fill = new PictureFill(DXImage.FromStream(stream));
fill.Stretch = true;
shape.Fill = fill;
}
}
presentation.Slides.Add(slide3);
presentation.HeaderFooterManager.AddSlideNumberPlaceholder(presentation.Slides);
presentation.HeaderFooterManager.AddFooterPlaceholder(presentation.Slides, "ProductXCompany");
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));
}
}