Use PowerPoint slides in C# and VB.NET

To enable a more consistent look and feel for presentation slides, the slides are organized in a hierarchy: master slides, layout slides and slides. Each slide in the hierarchy can define formatting or placeholders that are inherited by the descendant slides.

For more information about master slides, layout slides and slides, see the GemBox.Presentation content model help page.

The following C# and VB.NET example shows how to create and customize master slides, layout slides and slides using the GemBox.Presentation API.

Screenshot

PowerPoint Library for C# / VB.NET Screenshot

See the full code below, use RUN EXAMPLE to execute.


1using System;
2using System.IO;
3using System.Linq;
4using GemBox.Presentation;
5using GemBox.Presentation.Media;
6
7class Sample
8{
9    [STAThread]
10    static void Main(string[] args)
11    {
12        // If using Professional version, put your serial key below.
13        ComponentInfo.SetLicense("FREE-LIMITED-KEY");
14
15        PresentationDocument presentation = new PresentationDocument();
16
17        // Get slide size.
18        SlideSize size = presentation.SlideSize;
19
20        // Set slide size.
21        size.SizedFor = SlideSizeType.OnscreenShow16X10;
22        size.Orientation = Orientation.Landscape;
23        size.NumberSlidesFrom = 1;
24
25        // Create new master slide.
26        MasterSlide master = presentation.MasterSlides.AddNew();
27
28        // Create new layout slide for existing master slide.
29        LayoutSlide layout = master.LayoutSlides.AddNew(SlideLayoutType.TitleAndObject);
30
31        // Create new slide from existing template layout slide.
32        Slide slide = presentation.Slides.AddNew(layout);
33
34        // If master slide collection is empty, this method will add a new master slide.
35        // If layout slide collection of the last master slide doesn't contain a layout slide with the specified type, 
36        // then a new layout slide with the specified type will be added.
37        slide = presentation.Slides.AddNew(SlideLayoutType.TwoTextAndTwoObjects);
38
39        presentation.Save("Slides.pptx");
40    }
41}
1Imports System.IO
2Imports GemBox.Presentation
3Imports GemBox.Presentation.Media
4
5Module Samples
6
7    Sub Main()
8
9        ' If using Professional version, put your serial key below.
10        ComponentInfo.SetLicense("FREE-LIMITED-KEY")
11
12        Dim presentation As PresentationDocument = New PresentationDocument
13
14        ' Get slide size.
15        Dim size As SlideSize = presentation.SlideSize
16
17        ' Set slide size.
18        size.SizedFor = SlideSizeType.OnscreenShow16X10
19        size.Orientation = Orientation.Landscape
20        size.NumberSlidesFrom = 1
21
22        ' Create New master slide.
23        Dim master As MasterSlide = presentation.MasterSlides.AddNew()
24
25        ' Create New layout slide for existing master slide.
26        Dim layout As LayoutSlide = master.LayoutSlides.AddNew(SlideLayoutType.TitleAndObject)
27
28        ' Create New slide from existing template layout slide.
29        Dim slide As Slide = presentation.Slides.AddNew(layout)
30
31        ' If master slide collection is empty, this method will add a new master slide.
32        ' If layout slide collection of the last master slide doesn't contain a layout slide with the specified type, 
33        ' then a new layout slide with the specified type will be added.
34        slide = presentation.Slides.AddNew(SlideLayoutType.TwoTextAndTwoObjects)
35
36        presentation.Save("Slides.pptx")
37
38    End Sub
39
40End Module

Check next sample or find out more about GemBox.Presentation and GemBox Software.