LayoutSlide / MasterSlide

LayoutSlide and MasterSlide — Aspose.Slides FOSS Python API Reference

Every slide in a presentation is built on a three-level template hierarchy: MasterSlideLayoutSlideSlide. Masters define the overall theme, layouts define the content arrangement, and slides hold the actual content.

Package: aspose.slides_foss


LayoutSlide

A LayoutSlide defines the content-arrangement template applied to one or more Slide objects. It is not created directly; layouts are accessed through prs.layout_slides or through a master’s .layout_slides collection.

LayoutSlide Properties

PropertyTypeAccessDescription
master_slideMasterSlideReadThe master slide that owns this layout.
layout_typeSlideLayoutTypeReadThe predefined layout type (e.g. BLANK, TITLE, TITLE_ONLY).
shapesShapeCollectionReadShapes defined on this layout (inherited by slides using it).
namestrRead/WriteThe name of the layout slide.
slide_idintReadNumeric identifier extracted from the part name.
presentationPresentationReadThe parent Presentation object.

MasterSlide

A MasterSlide holds the theme, background, and default formatting shared by all layouts and slides that reference it. Accessed via prs.masters.

MasterSlide Properties

PropertyTypeAccessDescription
layout_slidesMasterLayoutSlideCollectionReadAll layout slides belonging to this master.
shapesShapeCollectionReadShapes placed on the master (appear on every slide using it).
namestrRead/WriteThe name of the master slide.
slide_idintReadNumeric identifier extracted from the part name.
presentationPresentationReadThe parent Presentation object.

LayoutSlideCollection

LayoutSlideCollection is the base collection class for layout slides. The GlobalLayoutSlideCollection (returned by prs.layout_slides) extends it.

LayoutSlideCollection Methods

MethodSignatureDescription
get_by_type(type: SlideLayoutType) -> LayoutSlide | NoneReturn the first layout matching the given SlideLayoutType.
__getitem__[index: int] -> LayoutSlideReturn layout slide at zero-based index.
__len__() -> intNumber of layouts in the collection.
__iter__N/AIterate over all layout slides.

GlobalLayoutSlideCollection

GlobalLayoutSlideCollection (returned by prs.layout_slides) is a flat view of all layout slides across all masters in the presentation.


MasterSlideCollection

MasterSlideCollection (returned by prs.masters) manages the set of master slides for the entire presentation.

MasterSlideCollection Methods

MethodSignatureDescription
add_clone(source_master: MasterSlide) -> MasterSlideClone a master slide (and all its layouts) from another presentation into this one.
__getitem__[index: int] -> MasterSlideReturn master slide at zero-based index.
__len__() -> intNumber of master slides.
__iter__N/AIterate over all master slides.

SlideLayoutType Enum

Imported from aspose.slides_foss.

MemberDescription
CUSTOMCustom layout
TITLETitle slide
BLANKBlank
TITLE_ONLYTitle only
SECTION_HEADERSection header
PICTURE_AND_CAPTIONPicture and caption
TWO_OBJECTSTwo objects
TEXTText
TABLETable
CHARTChart
DIAGRAMDiagram

(All 41 members are defined in SlideLayoutType.py.)


Code Examples

Inspect All Layouts in a Presentation

import aspose.slides_foss as slides

with slides.Presentation("deck.pptx") as prs:
    print(f"Masters: {len(prs.masters)}")
    for master in prs.masters:
        print(f"  Master: {master.name!r}")
        for layout in master.layout_slides:
            print(f"    Layout: {layout.name!r}  type={layout.layout_type}")

Add a Slide Using a Specific Layout Type

import aspose.slides_foss as slides
from aspose.slides_foss import SlideLayoutType
from aspose.slides_foss.export import SaveFormat

with slides.Presentation() as prs:
    # Find the blank layout
    blank_layout = prs.layout_slides.get_by_type(SlideLayoutType.BLANK)
    if blank_layout is None:
        blank_layout = prs.layout_slides[0]   # fallback

    new_slide = prs.slides.add_empty_slide(blank_layout)
    new_slide.shapes.add_auto_shape(
        slides.ShapeType.RECTANGLE, 50, 50, 400, 200
    )
    prs.save("blank-slide.pptx", SaveFormat.PPTX)

Clone a Master from Another Presentation

import aspose.slides_foss as slides
from aspose.slides_foss.export import SaveFormat

with slides.Presentation("source.pptx") as src, \
     slides.Presentation("target.pptx") as tgt:
    source_master = src.masters[0]
    tgt.masters.add_clone(source_master)
    tgt.save("target-updated.pptx", SaveFormat.PPTX)

Access the Layout and Master of an Existing Slide

import aspose.slides_foss as slides

with slides.Presentation("deck.pptx") as prs:
    slide = prs.slides[0]
    layout = slide.layout_slide
    master = slide.master_slide
    print(f"Layout: {layout.name!r}  ({layout.layout_type})")
    print(f"Master: {master.name!r}")

See Also