Placeholders

Placeholders are special drawings that establish a connection between a slide and its parent layout slide, thus enabling users to specify common properties like layout or formatting in a single place (the layout slide). These settings are automatically propagated to all slides whose template parent is that layout slide. A slide can be synchronized with its parent layout slide by calling the Reset method.

The following example shows how to create and customize placeholders using the GemBox.Presentation API.

Screenshot
PowerPoint Library for C# / VB.NET Screenshot

See the full code below, use Run Example to execute.

using System;
using System.IO;
using System.Linq;
using GemBox.Presentation;
using GemBox.Presentation.Media;

class Sample
{
    [STAThread]
    static void Main(string[] args)
    {
        // If using Professional version, put your serial key below.
        ComponentInfo.SetLicense("FREE-LIMITED-KEY");

        PresentationDocument presentation = new PresentationDocument();

        // Create new master slide.
        MasterSlide master = presentation.MasterSlides.AddNew();

        // Create new empty layout slide for existing master slide.
        LayoutSlide layout = master.LayoutSlides.AddNew(SlideLayoutType.Custom);

        // Create title and subtitle placeholders on layout slide.
        layout.Content.AddPlaceholder(PlaceholderType.Title);
        layout.Content.AddPlaceholder(PlaceholderType.Subtitle);

        // Create new slide; will inherit all placeholders (title and subtitle) from template layout slide.
        Slide slide = presentation.Slides.AddNew(layout);

        // Retrieve "Title" placeholder.
        Shape shape = slide.Content.Drawings.OfType<Shape>().Where(item => item.Placeholder?.PlaceholderType == PlaceholderType.Title).First();

        // Set shape fill and outline format.
        shape.Format.Outline.Fill.SetSolid(Color.FromName(ColorName.DarkGray));
        shape.Format.Fill.SetSolid(Color.FromName(ColorName.LightGray));

        // Set shape text.
        shape.Text.AddParagraph().AddRun("Placeholders, GemBox.Presentation");

        // Retrieve "Subtitle" placeholder.
        shape = slide.Content.Drawings.OfType<Shape>().Where(item => item.Placeholder?.PlaceholderType == PlaceholderType.Subtitle).First();

        // Set shape outline format.
        shape.Format.Outline.Fill.SetSolid(Color.FromName(ColorName.DarkGray));

        // Set shape text.
        shape.Text.AddParagraph().AddRun("Shows how to use placeholders with GemBox.Presentation component.");

        presentation.Save("Placeholders.pptx");
    }
}
Imports System.IO
Imports GemBox.Presentation
Imports GemBox.Presentation.Media

Module Samples

    Sub Main()

        ' If using Professional version, put your serial key below.
        ComponentInfo.SetLicense("FREE-LIMITED-KEY")

        Dim presentation As PresentationDocument = New PresentationDocument

        ' Create New master slide.
        Dim master As MasterSlide = presentation.MasterSlides.AddNew()

        ' Create New empty layout slide for existing master slide.
        Dim layout As LayoutSlide = master.LayoutSlides.AddNew(SlideLayoutType.Custom)

        ' Create title And subtitle placeholders on layout slide.
        layout.Content.AddPlaceholder(PlaceholderType.Title)
        layout.Content.AddPlaceholder(PlaceholderType.Subtitle)

        ' Create New slide; will inherit all placeholders (title And subtitle) from template layout slide.
        Dim slide As Slide = presentation.Slides.AddNew(layout)

        ' Retrieve "Title" placeholder.
        Dim shape As Shape = slide.Content.Drawings.OfType(Of Shape).Where(Function(item) item.Placeholder?.PlaceholderType = PlaceholderType.Title).First()

        ' Set shape fill And outline format.
        shape.Format.Outline.Fill.SetSolid(Color.FromName(ColorName.DarkGray))
        shape.Format.Fill.SetSolid(Color.FromName(ColorName.LightGray))

        ' Set shape text.
        shape.Text.AddParagraph().AddRun("Placeholders, GemBox.Presentation")

        ' Retrieve "Subtitle" placeholder.
        shape = slide.Content.Drawings.OfType(Of Shape).Where(Function(item) item.Placeholder?.PlaceholderType = PlaceholderType.Subtitle).First()

        ' Set shape outline format.
        shape.Format.Outline.Fill.SetSolid(Color.FromName(ColorName.DarkGray))

        ' Set shape text.
        shape.Text.AddParagraph().AddRun("Shows how to use placeholders with GemBox.Presentation component.")

        presentation.Save("Placeholders.pptx")

    End Sub

End Module