Slide Layout
A slide layout contains the placeholder boxes and formatting information for all the content that appears on a slide. The layout determines the available content placeholders and where they are placed.
Slide layouts allow you to create and design presentations quickly (whether simple or complex). These are some of the most popular slide layouts used in PowerPoint presentations:
- Title Slide layout. This layout consists of two text placeholders. One placeholder is for the title and the other is for the subtitle.
- Title and Content layout. This layout contains a relatively small placeholder at the top for the title and a bigger placeholder for the core content (chart, paragraphs, bullet list, numbered list, images, etc).
- Blank layout. This layout lacks placeholders, so it allows you to create elements from scratch.
Since a slide master is the top hierarchical slide that stores information about slide layouts, you can use the master slide to access slide layouts and make changes to them. A layout slide can be accessed by type or name. Similarly, every slide has a unique id, which can be used to access it.
Alternatively, you can make changes directly to a specific slide layout in a presentation.
- To allow you to work with slide layouts (including those in master slides), Aspose.Slides provides properties like LayoutSlides and Masters under the Presentation class.
- To perform related tasks, Aspose.Slides provides MasterSlide, MasterLayoutSlideCollection, SlideSize, BaseSlideHeaderFooterManager, and many other types.
Info
For more information on working with Master Slides in particular, see the Slide Master article.Add Slide Layout to Presentation
- Create an instance of the Presentation class.
- Access the MasterSlide collection.
- Go through the existing layout slides to confirm that the required layout slide already exists in the Layout Slide collection. Otherwise, add the Layout slide you want.
- Add an empty slide based on the new layout slide.
- Save the presentation.
This C# code shows you how to add a slide layout to a PowerPoint presentation:
// Instantiates a Presentation class that represents the presentation file
using (Presentation presentation = new Presentation("AccessSlides.pptx"))
{
// Goes through layout slide types
IMasterLayoutSlideCollection layoutSlides = presentation.Masters[0].LayoutSlides;
ILayoutSlide layoutSlide = layoutSlides.GetByType(SlideLayoutType.TitleAndObject) ?? layoutSlides.GetByType(SlideLayoutType.Title);
if (layoutSlide == null)
{
// The situation where a presentation doesn't contain some layout types.
// presentation File only contains Blank and Custom layout types.
// But layout slides with Custom types have different slide names,
// like "Title", "Title and Content", etc. And it is possible to use these
// names for layout slide selection.
// You can also use a 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);
if (layoutSlide == null)
{
layoutSlide = layoutSlides.Add(SlideLayoutType.TitleAndObject, "Title and Object");
}
}
}
}
// Adds empty slide with added layout slide
presentation.Slides.InsertEmptySlide(0, layoutSlide);
// Saves the presentation to disk
presentation.Save("AddLayoutSlides_out.pptx", SaveFormat.Pptx);
}
Remove Unused Layout Slide
Aspose.Slides provides the RemoveUnusedLayoutSlides method from the Compress class to allow you to delete unwanted and unused layout slides. This C# code shows you how to remove a layout slide from a PowerPoint presentation:
using (Presentation pres = new Presentation("pres.pptx"))
{
Aspose.Slides.LowCode.Compress.RemoveUnusedLayoutSlides(pres);
pres.Save("pres-out.pptx", SaveFormat.Pptx);
}
Set Size and Type for Slide Layout
To allow you to set the size and type for a specific layout slide, Aspose.Slides provides the Type and Size properties (from the Presentation class). This C# demonstrates the operation:
// Instantiates a Presentation object that represents a presentation file
Presentation presentation = new Presentation("AccessSlides.pptx");
Presentation auxPresentation = new Presentation();
ISlide slide = presentation.Slides[0];
// Sets the slide size for the generated presentation to that of the source
auxPresentation.SlideSize.SetSize(presentation.SlideSize.Type,SlideSizeScaleType.EnsureFit);
auxPresentation.Slides.InsertClone(0, slide);
auxPresentation.Slides.RemoveAt(0);
// Saves the presentation to disk
auxPresentation.Save("Set_Size&Type_out.pptx", SaveFormat.Pptx);
Set Footer Visibility Inside Slide
- Create an instance of the Presentation class.
- Get a slide’s reference through its index.
- Set the slide footer placeholder to visible.
- Set the date-time placeholder to visible.
- Save the presentation.
This C# code shows you how to set the visibility for a slide footer (and perform related tasks):
using (Presentation presentation = new Presentation("presentation.ppt"))
{
IBaseSlideHeaderFooterManager headerFooterManager = presentation.Slides[0].HeaderFooterManager;
if (!headerFooterManager.IsFooterVisible) // Property IsFooterVisible is used to specify that a slide footer placeholder is missing
{
headerFooterManager.SetFooterVisibility(true); // Method SetFooterVisibility is used to set a slide footer placeholder to visible
}
if (!headerFooterManager.IsSlideNumberVisible) // Property IsSlideNumberVisible is used to specify that a slide page number placeholder is missing
{
headerFooterManager.SetSlideNumberVisibility(true); // Method SetSlideNumberVisibility is used to set a slide page number placeholder to visible
}
if (!headerFooterManager.IsDateTimeVisible) // Property IsDateTimeVisible is used to specify that a slide date-time placeholder is missing
{
headerFooterManager.SetDateTimeVisibility(true); // Method SetFooterVisibility is used to set a slide date-time placeholder to visible
}
headerFooterManager.SetFooterText("Footer text"); // Method SetFooterText is used to set a text for a slide footer placeholder
headerFooterManager.SetDateTimeText("Date and time text"); // Method SetDateTimeText is used to set a text for a slide date-time placeholder.
presentation.Save("Presentation.ppt",SaveFormat.ppt);
}
Set Child Footer Visibility Inside Slide
- Create an instance of the Presentation class.
- Get a reference for the master slide through its index.
- Set the master slide and all child footer placeholders to visible.
- Set a text for the master slide and all child footer placeholders.
- Set a text for the master slide and all child date-time placeholders.
- Save the presentation.
This C# code demonstrates the operation:
using (Presentation presentation = new Presentation("presentation.ppt"))
{
IMasterSlideHeaderFooterManager headerFooterManager = presentation.Masters[0].HeaderFooterManager;
headerFooterManager.SetFooterAndChildFootersVisibility(true); // Method SetFooterAndChildFootersVisibility is used to set the master slide and all child footer placeholders to visible
headerFooterManager.SetSlideNumberAndChildSlideNumbersVisibility(true); // Method SetSlideNumberAndChildSlideNumbersVisibility is used to set the master slide and all child page number placeholders to visible
headerFooterManager.SetDateTimeAndChildDateTimesVisibility(true); // Method SetDateTimeAndChildDateTimesVisibility is used to set a master slide and all child date-time placeholders to visible
headerFooterManager.SetFooterAndChildFootersText("Footer text"); // Method SetFooterAndChildFootersText is used to set texts for the master slide and all child footer placeholders
headerFooterManager.SetDateTimeAndChildDateTimesText("Date and time text"); // Method SetDateTimeAndChildDateTimesText is used to set text for the master slide and all child date-time placeholders
}
Set Slide Size with Respect to Content Scaling
- Create an instance of the Presentation class and load the presentation containing the slide whose size you want to set.
- Create another instance of the Presentation class to generate a new presentation.
- Get the slide’s reference (from the first presentation) through its index.
- Set the slide footer placeholder to visible.
- Set the date-time placeholder to visible.
- Save the presentation.
This C# demonstrates the operation:
// Instantiates a Presentation object that represents a presentation file
Presentation presentation = new Presentation("AccessSlides.pptx");
Presentation auxPresentation = new Presentation();
ISlide slide = presentation.Slides[0];
// Sets the slide size for the generated presentations to that of the source
presentation.SlideSize.SetSize(540, 720, SlideSizeScaleType.EnsureFit); // Method SetSize is used to set slide size with scale content to ensure fit
presentation.SlideSize.SetSize(SlideSizeType.A4Paper, SlideSizeScaleType.Maximize); // Method SetSize is used to set slide size with maximum size of content
// Saves the presentation to disk
auxPresentation.Save("Set_Size&Type_out.pptx", SaveFormat.Pptx);
Set Page Size when Generating PDF
Certain presentations (like posters) are often converted to PDF docs. If you are looking to convert your PowerPoint to PDF to access the best printing and accessibility options, you want to set your slides to sizes that suit PDF documents (A4, for example).
Aspose.Slides provides the SlideSize class to allow you to specify your preferred settings for slides. This C# code shows you how to use the Type property (from the SlideSize
class) to set a specific paper size for the slides in a presentation:
// Instantiates a Presentation object that represents a presentation file
Presentation presentation = new Presentation();
// Sets the SlideSize.Type Property
presentation.SlideSize.SetSize(SlideSizeType.A4Paper,SlideSizeScaleType.EnsureFit);
// Sets different properties for PDF Options
PdfOptions opts = new PdfOptions();
opts.SufficientResolution = 600;
// Saves the presentation to disk
presentation.Save("SetPDFPageSize_out.pdf", SaveFormat.Pdf, opts);