Back to Devexpress

Create Your First Presentation with DevExpress Presentation API Library

officefileapi-405404-presentation-api-create-first-presentation.md

latest26.7 KB
Original Source

Create Your First Presentation with DevExpress Presentation API Library

  • Dec 24, 2025
  • 11 minutes to read

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.

View Example

Create a .NET Application

  1. Start Visual Studio and create a new Console Application project.

  2. Install the DevExpress.Docs.Presentation package.

Read Tutorial: Choose Between Offline and Online DevExpress NuGet Feeds

Create a .NET Framework Application

  1. Start Visual Studio and create a new Console Application (.NET Framework) project.

  2. 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):

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:

csharp
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();
    }
}
vb
Imports DevExpress.Docs.Presentation
Imports DevExpress.Drawing
Imports System.Drawing
Imports System.IO

Namespace DxPresentationGetStarted

    Public Class Program

        Public Shared Sub Main(ByVal underscore() As String)
            ' Creates a presentation with a single empty slide.
            Dim presentation As New Presentation()
        End Sub

    End Class

End Namespace

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.

csharp
SlideMaster slideMaster = presentation.SlideMasters[0];
slideMaster.Background = new CustomSlideBackground(new SolidFill(Color.FromArgb(194, 228, 249)));
vb
Dim slideMaster As 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:

csharp
presentation.Slides.Clear();
vb
presentation.Slides.Clear()

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.

csharp
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);
vb
Dim slide1 As Slide = New Slide(slideMaster.Layouts.Get(SlideLayoutType.Title))
For Each shape As Shape In slide1.Shapes
    If TypeOf shape.PlaceholderSettings.Type Is PlaceholderType.CenteredTitle Then
        shape.TextArea = New TextArea("Daily Testing Status Report")
    End If
    If TypeOf shape.PlaceholderSettings.Type Is PlaceholderType.Subtitle Then
        shape.TextArea = New TextArea($"{Date.Now: dddd, MMMM d, yyyy}")
    End If
Next
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.

csharp
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.Body) {
        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);
vb
Dim slide2 As Slide = New Slide(slideMaster.Layouts.GetOrCreate(SlideLayoutType.Object))
For Each shape As Shape In slide2.Shapes
    If TypeOf shape.PlaceholderSettings.Type Is PlaceholderType.Title Then
        shape.TextArea = New TextArea("Today’s Highlights")
    End If
    If TypeOf shape.PlaceholderSettings.Type Is PlaceholderType.Body Then
        Dim textArea As 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
    End If
Next
presentation.Slides.Add(slide2)

Add Slide #3

The third slide displays a caption and a table.

  • 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 a table instead of the default Body placeholder, follow these steps:

  • Add the resulting slide to the presentation’s Slides collection.

csharp
Slide slide3 = new Slide(slideMaster.Layouts.GetOrCreate(SlideLayoutType.Object));
foreach (Shape shape in slide3.Shapes.ToList()) {
    if (shape.PlaceholderSettings.Type is PlaceholderType.Title) {
        shape.TextArea = new TextArea("Build Status");
    }
    if (shape.PlaceholderSettings.Type is PlaceholderType.Body) {

        RectangleF rect = presentation.GetActualShapeBounds(slide3, shape);
        slide3.Shapes.Remove(shape);

        Table table = new Table(5, 5, rect.X, rect.Y, rect.Width, rect.Height);
        slide3.Shapes.Add(table);

        table[0, 0].TextArea.Text = "Build ID";
        table[0, 1].TextArea.Text = "Branch";
        table[0, 2].TextArea.Text = "Status";
        table[0, 3].TextArea.Text = "Duration";
        table[0, 4].TextArea.Text = "Triggered By";

        table[1, 0].TextArea.Text = "#5421";
        table[1, 1].TextArea.Text = "main";
        table[1, 2].TextArea.Text = "✅ Passed";
        table[1, 3].TextArea.Text = "4m 30s";
        table[1, 4].TextArea.Text = "Auto-schedule";

        table[2, 0].TextArea.Text = "#5420";
        table[2, 1].TextArea.Text = "ui-fix";
        table[2, 2].TextArea.Text = "❌ Failed";
        table[2, 3].TextArea.Text = "2m 18s";
        table[2, 4].TextArea.Text = "Push by dev1";

        table[3, 0].TextArea.Text = "#5419";
        table[3, 1].TextArea.Text = "main";
        table[3, 2].TextArea.Text = "✅ Passed";
        table[3, 3].TextArea.Text = "3m 52s";
        table[3, 4].TextArea.Text = "Auto-schedule";

        table[4, 0].TextArea.Text = "#5418";
        table[4, 1].TextArea.Text = "hotfix";
        table[4, 2].TextArea.Text = "❌ Failed";
        table[4, 3].TextArea.Text = "5m 1s";
        table[4, 4].TextArea.Text = "Manual";

        table.Style = new ThemedTableStyle(TableStyleType.LightStyle1);
        table.HasBandedRows = false;
    }
}
presentation.Slides.Add(slide3);
vb
Dim slide3 As Slide = New Slide(slideMaster.Layouts.GetOrCreate(SlideLayoutType.Object))
For Each shape As Shape In slide3.Shapes.ToList()
    If shape.PlaceholderSettings.Type = PlaceholderType.Title Then
        shape.TextArea = New TextArea("Build Status")
    End If
    If shape.PlaceholderSettings.Type = PlaceholderType.Body Then

        Dim rect = presentation.GetActualShapeBounds(slide3, shape)
        slide3.Shapes.Remove(shape)

        Dim table As Table = New Table(5, 5, rect.X, rect.Y, rect.Width, rect.Height)
        slide3.Shapes.Add(table)

        table(0, 0).TextArea.Text = "Build ID"
        table(0, 1).TextArea.Text = "Branch"
        table(0, 2).TextArea.Text = "Status"
        table(0, 3).TextArea.Text = "Duration"
        table(0, 4).TextArea.Text = "Triggered By"

        table(1, 0).TextArea.Text = "#5421"
        table(1, 1).TextArea.Text = "main"
        table(1, 2).TextArea.Text = "✅ Passed"
        table(1, 3).TextArea.Text = "4m 30s"
        table(1, 4).TextArea.Text = "Auto-schedule"

        table(2, 0).TextArea.Text = "#5420"
        table(2, 1).TextArea.Text = "ui-fix"
        table(2, 2).TextArea.Text = "❌ Failed"
        table(2, 3).TextArea.Text = "2m 18s"
        table(2, 4).TextArea.Text = "Push by dev1"

        table(3, 0).TextArea.Text = "#5419"
        table(3, 1).TextArea.Text = "main"
        table(3, 2).TextArea.Text = "✅ Passed"
        table(3, 3).TextArea.Text = "3m 52s"
        table(3, 4).TextArea.Text = "Auto-schedule"

        table(4, 0).TextArea.Text = "#5418"
        table(4, 1).TextArea.Text = "hotfix"
        table(4, 2).TextArea.Text = "❌ Failed"
        table(4, 3).TextArea.Text = "5m 1s"
        table(4, 4).TextArea.Text = "Manual"

        table.Style = New ThemedTableStyle(TableStyleType.LightStyle1)
        table.HasBandedRows = False
    End If
Next
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.

csharp
presentation.HeaderFooterManager.AddSlideNumberPlaceholder(presentation.Slides);
presentation.HeaderFooterManager.AddFooterPlaceholder(presentation.Slides, "ProductXCompany");
vb
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:

csharp
FileStream outputStream = new FileStream(@"..\..\..\data\my-presentation.pptx", FileMode.Create);
presentation.SaveDocument(outputStream);
outputStream.Dispose();
vb
Dim outputStream As 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:

csharp
presentation.ExportToPdf(new FileStream(@"..\..\..\data\exported-document.pdf", FileMode.Create));
vb
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 sample:

View Example

csharp
using DevExpress.Docs.Presentation;
using DevExpress.Drawing;
using System.Drawing;

namespace DxPresentationGetStarted;

public class Program {
    public static void Main(string[] _) {

        // Create a new presentation and remove the default empty slide
        Presentation presentation = new Presentation();
        presentation.Slides.Clear();

        // Specify a custom background color for the slide master to share this background across all child slides
        SlideMaster slideMaster = presentation.SlideMasters[0];
        slideMaster.Background = new CustomSlideBackground(new SolidFill(Color.FromArgb(194, 228, 249)));

        // Create a slide with the Title layout
        Slide slide1 = new Slide(slideMaster.Layouts.Get(SlideLayoutType.Title));
        foreach (Shape shape in slide1.Shapes) {
            // Specify the centered title text
            if (shape.PlaceholderSettings.Type is PlaceholderType.CenteredTitle) {
                shape.TextArea = new TextArea("Daily Testing Status Report");
            }
            // Set the subtitle to the current date
            if (shape.PlaceholderSettings.Type is PlaceholderType.Subtitle) {
                shape.TextArea = new TextArea($"{DateTime.Now: dddd, MMMM d, yyyy}");
            }
        }
        presentation.Slides.Add(slide1);

        // Create a slide based on the Object layout
        Slide slide2 = new Slide(slideMaster.Layouts.GetOrCreate(SlideLayoutType.Object));
        foreach (Shape shape in slide2.Shapes) {
            // Specify the slide title
            if (shape.PlaceholderSettings.Type is PlaceholderType.Title) {
                shape.TextArea = new TextArea("Today’s Highlights");
            }
            // Add a list of paragraphs to the slide
            if (shape.PlaceholderSettings.Type is PlaceholderType.Body) {
                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);

        // Create a slide based on the Object layout
        Slide slide3 = new Slide(slideMaster.Layouts.GetOrCreate(SlideLayoutType.Object));
        foreach (Shape shape in slide3.Shapes.ToList()) {
            // Specify the slide title
            if (shape.PlaceholderSettings.Type is PlaceholderType.Title) {
                shape.TextArea = new TextArea("Build Status");
            }
            // Add a table to a slide placeholder
            if (shape.PlaceholderSettings.Type is PlaceholderType.Body) {
                RectangleF rect = presentation.GetActualShapeBounds(slide3, shape);
                slide3.Shapes.Remove(shape);

                Table table = new Table(5, 5, rect.X, rect.Y, rect.Width, rect.Height);
                slide3.Shapes.Add(table);

                table[0, 0].TextArea.Text = "Build ID";
                table[0, 1].TextArea.Text = "Branch";
                table[0, 2].TextArea.Text = "Status";
                table[0, 3].TextArea.Text = "Duration";
                table[0, 4].TextArea.Text = "Triggered By";

                table[1, 0].TextArea.Text = "#5421";
                table[1, 1].TextArea.Text = "main";
                table[1, 2].TextArea.Text = "✅ Passed";
                table[1, 3].TextArea.Text = "4m 30s";
                table[1, 4].TextArea.Text = "Auto-schedule";

                table[2, 0].TextArea.Text = "#5420";
                table[2, 1].TextArea.Text = "ui-fix";
                table[2, 2].TextArea.Text = "❌ Failed";
                table[2, 3].TextArea.Text = "2m 18s";
                table[2, 4].TextArea.Text = "Push by dev1";

                table[3, 0].TextArea.Text = "#5419";
                table[3, 1].TextArea.Text = "main";
                table[3, 2].TextArea.Text = "✅ Passed";
                table[3, 3].TextArea.Text = "3m 52s";
                table[3, 4].TextArea.Text = "Auto-schedule";

                table[4, 0].TextArea.Text = "#5418";
                table[4, 1].TextArea.Text = "hotfix";
                table[4, 2].TextArea.Text = "❌ Failed";
                table[4, 3].TextArea.Text = "5m 1s";
                table[4, 4].TextArea.Text = "Manual";

                table.Style = new ThemedTableStyle(TableStyleType.LightStyle1);
                table.HasBandedRows = false;
            }
        }
        presentation.Slides.Add(slide3);

        // Add slide numbers and a footer to all slides
        presentation.HeaderFooterManager.AddSlideNumberPlaceholder(presentation.Slides);
        presentation.HeaderFooterManager.AddFooterPlaceholder(presentation.Slides, "ProductXCompany");

        // Save the presentation to a PPTX file
        FileStream outputStream = new FileStream(@"..\..\..\data\my-presentation.pptx", FileMode.Create);
        presentation.SaveDocument(outputStream);
        outputStream.Dispose();

        // Export the presentation to PDF
        presentation.ExportToPdf(new FileStream(@"..\..\..\data\exported-document.pdf", FileMode.Create));
    }
}
vb
Imports DevExpress.Docs.Presentation
Imports DevExpress.Drawing
Imports System.Drawing

Namespace DxPresentationGetStarted

    Public Class Program
        Public Shared Sub Main(__ As String())

            ' Create a new presentation and remove the default empty slide
            Dim presentation As Presentation = New Presentation()
            presentation.Slides.Clear()

            ' Specify a custom background color for the slide master to share this background across all child slides
            Dim slideMaster = presentation.SlideMasters(0)
            slideMaster.Background = New CustomSlideBackground(New SolidFill(Color.FromArgb(194, 228, 249)))

            ' Create a slide with the Title layout
            Dim slide1 As Slide = New Slide(slideMaster.Layouts.Get(SlideLayoutType.Title))
            For Each shape As Shape In slide1.Shapes
                ' Specify the centered title text
                If TypeOf shape.PlaceholderSettings.Type Is PlaceholderType.CenteredTitle Then
                    shape.TextArea = New TextArea("Daily Testing Status Report")
                End If
                ' Set the subtitle to the current date
                If TypeOf shape.PlaceholderSettings.Type Is PlaceholderType.Subtitle Then
                    shape.TextArea = New TextArea($"{Date.Now: dddd, MMMM d, yyyy}")
                End If
            Next
            presentation.Slides.Add(slide1)

            ' Create a slide based on the Object layout
            Dim slide2 As Slide = New Slide(slideMaster.Layouts.GetOrCreate(SlideLayoutType.Object))
            For Each shape As Shape In slide2.Shapes
                ' Specify the slide title
                If TypeOf shape.PlaceholderSettings.Type Is PlaceholderType.Title Then
                    shape.TextArea = New TextArea("Today’s Highlights")
                End If
                ' Add a list of paragraphs to the slide
                If TypeOf shape.PlaceholderSettings.Type Is PlaceholderType.Body Then
                    Dim textArea As 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
                End If
            Next
            presentation.Slides.Add(slide2)

            ' Create a slide based on the Object layout
            Dim slide3 As Slide = New Slide(slideMaster.Layouts.GetOrCreate(SlideLayoutType.Object))
            For Each shape As Shape In slide3.Shapes.ToList()
                ' Specify the slide title
                If shape.PlaceholderSettings.Type = PlaceholderType.Title Then
                    shape.TextArea = New TextArea("Build Status")
                End If
                ' Add a table to a slide placeholder
                If shape.PlaceholderSettings.Type = PlaceholderType.Body Then

                    Dim rect = presentation.GetActualShapeBounds(slide3, shape)
                    slide3.Shapes.Remove(shape)

                    Dim table As Table = New Table(5, 5, rect.X, rect.Y, rect.Width, rect.Height)
                    slide3.Shapes.Add(table)

                    table(0, 0).TextArea.Text = "Build ID"
                    table(0, 1).TextArea.Text = "Branch"
                    table(0, 2).TextArea.Text = "Status"
                    table(0, 3).TextArea.Text = "Duration"
                    table(0, 4).TextArea.Text = "Triggered By"

                    table(1, 0).TextArea.Text = "#5421"
                    table(1, 1).TextArea.Text = "main"
                    table(1, 2).TextArea.Text = "✅ Passed"
                    table(1, 3).TextArea.Text = "4m 30s"
                    table(1, 4).TextArea.Text = "Auto-schedule"

                    table(2, 0).TextArea.Text = "#5420"
                    table(2, 1).TextArea.Text = "ui-fix"
                    table(2, 2).TextArea.Text = "❌ Failed"
                    table(2, 3).TextArea.Text = "2m 18s"
                    table(2, 4).TextArea.Text = "Push by dev1"

                    table(3, 0).TextArea.Text = "#5419"
                    table(3, 1).TextArea.Text = "main"
                    table(3, 2).TextArea.Text = "✅ Passed"
                    table(3, 3).TextArea.Text = "3m 52s"
                    table(3, 4).TextArea.Text = "Auto-schedule"

                    table(4, 0).TextArea.Text = "#5418"
                    table(4, 1).TextArea.Text = "hotfix"
                    table(4, 2).TextArea.Text = "❌ Failed"
                    table(4, 3).TextArea.Text = "5m 1s"
                    table(4, 4).TextArea.Text = "Manual"

                    table.Style = New ThemedTableStyle(TableStyleType.LightStyle1)
                    table.HasBandedRows = False
                End If
            Next
            presentation.Slides.Add(slide3)

            ' Add slide numbers and a footer to all slides
            presentation.HeaderFooterManager.AddSlideNumberPlaceholder(presentation.Slides)
            presentation.HeaderFooterManager.AddFooterPlaceholder(presentation.Slides, "ProductXCompany")

            ' Save the presentation to a PPTX file
            Dim outputStream As FileStream = New FileStream("..\..\..\data\my-presentation.pptx", FileMode.Create)
            presentation.SaveDocument(outputStream)
            outputStream.Dispose()

            ' Export the presentation to PDF
            presentation.ExportToPdf(New FileStream("..\..\..\data\exported-document.pdf", FileMode.Create))
        End Sub
    End Class
End Namespace