Layout Slide

This article demonstrates how to work with Layout Slides in Aspose.Slides for Python via .NET. A layout slide defines the design and formatting inherited by normal slides. You can add, access, clone, and remove layout slides, as well as clean up unused ones to reduce presentation size.

Add a Layout Slide

You can create a custom layout slide to define reusable formatting.

def add_layout_slide():
    with slides.Presentation() as presentation:
        master_slide = presentation.masters[0]
        layout_type = slides.SlideLayoutType.CUSTOM
        layout_name = "Main layout"

        # Create a layout slide with the specified type and name.
        layout_slide = presentation.layout_slides.add(master_slide, layout_type, layout_name)

        presentation.save("layout_slide.pptx", slides.export.SaveFormat.PPTX)

💡 Tip 1: Layout slides act as templates for individual slides. You can define common elements once and reuse them across many slides.

💡 Tip 2: When you add shapes or text to a layout slide, all slides based on that layout will display this shared content automatically. The screenshot below shows two slides, each inheriting a text box from the same layout slide.

Slides Inheriting Layout Content

Access a Layout Slide

Layout slides can be accessed by index or by layout type (e.g., Blank, Title, SectionHeader, etc.).

def access_layout_slide():
    with slides.Presentation("layout_slide.pptx") as presentation:

        # Access by index.
        first_layout_slide = presentation.layout_slides[0]

        # Access by layout type.
        blank_layout_slide = presentation.layout_slides.get_by_type(slides.SlideLayoutType.BLANK)

Remove a Layout Slide

You can remove a specific layout slide if it’s no longer needed.

def remove_layout_slide():
    with slides.Presentation("layout_slide.pptx") as presentation:

        # Get a layout slide by type and remove it.
        layout_slide = presentation.layout_slides.get_by_type(slides.SlideLayoutType.CUSTOM)
        presentation.layout_slides.remove(layout_slide)

        presentation.save("layout_slide_removed.pptx", slides.export.SaveFormat.PPTX)

Remove Unused Layout Slides

To reduce the presentation size, you may want to remove layout slides that are not used by any normal slides.

def remove_unused_layout_slides():
    with slides.Presentation("layout_slide.pptx") as presentation:

        # Automatically removes all layout slides not referenced by any slide.
        presentation.layout_slides.remove_unused()

        presentation.save("layout_slides_removed.pptx", slides.export.SaveFormat.PPTX)

Clone a Layout Slide

You can duplicate a layout slide using the AddClone method.

def clone_layout_slides():
    with slides.Presentation("layout_slide.pptx") as presentation:

        # Get an existing layout slide by type.
        layout_slide = presentation.layout_slides.get_by_type(slides.SlideLayoutType.BLANK)

        # Clone the layout slide to the end of the layout slide collection.
        cloned_layout_slide = presentation.layout_slides.add_clone(layout_slide)

        presentation.save("layout_slide_cloned.pptx", slides.export.SaveFormat.PPTX)

Summary: Layout slides are powerful tools for managing consistent formatting across slides. Aspose.Slides allows full control over creating, managing, and optimizing layout slides.