How to Add Layout Slides in PowerPoint Presentation inside .NET Apps

In This technical tip, we will learn how .NET developers can add Layout slides in presentation using Aspose.Slides inside their .NET applications. There are cases when there is missing Layout slide in presentation and once can now add the Layout Slides in presentation. Each slide has unique Id and Layout slides are maintained inside presentation Masters. One can access the Layout slide either by Type or by Name. Aspose.Slides for .NET allows developers to add new Layout slides in presentation.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
//your code here...//Adding Slides to the Presentation
//[C# Code Sample]
 
//Instantiate Presentation class that represents the presentation file
public static void AddLayoutSlide()
{
    string n = @"Test.pptx";
    //Instantiate Presentation class that represents the presentation file
    using (Presentation p = new Presentation(n))
    {
        // Try to search by layout slide type
        IMasterLayoutSlideCollection layoutSlides = p.Masters[0].LayoutSlides;
        ILayoutSlide layoutSlide =
            layoutSlides.GetByType(SlideLayoutType.TitleAndObject) ??
            layoutSlides.GetByType(SlideLayoutType.Title);
        if (layoutSlide == null)
        {
            // The situation when a presentation doesn't contain some type of layouts.
            // Technographics.pptx presentation only contains Blank and Custom layout types.
            // But layout slides with Custom types has different slide names,
            // like "Title", "Title and Content", etc. And it is possible to use these
            // names for layout slide selection.
            // Also it is possible to use the set of placeholder shape types. For example,
            // Title slide should have only Title pleceholder type, etc.
            foreach (ILayoutSlide titleAndObjectLayoutSlide in layoutSlides)
            {
                if (titleAndObjectLayoutSlide.Name == "Title and Object")
                {
                    layoutSlide = titleAndObjectLayoutSlide;
                    break;
                }
            }
            if (layoutSlide == null)
            {
                foreach (ILayoutSlide titleLayoutSlide in layoutSlides)
                {
                    if (titleLayoutSlide.Name == "Title")
                    {
                        layoutSlide = titleLayoutSlide;
                        break;
                    }
                }
                if (layoutSlide == null)
                {
                    layoutSlide = layoutSlides.GetByType(SlideLayoutType.Blank);
X

Language: C# | User: Sheraz Khan | Created: Dec 3, 2014 | Tags: add Layout slides in presentation Layout Slide collection reate an instance of Presentation Access the Master Slide collection find existing Layout slides dd a new Layout slide .NET PowerPoint API PowerPoint .NET Component