LayoutSlide and MasterSlide — Aspose.Slides FOSS Python API Reference
Every slide in a presentation is built on a three-level template hierarchy: MasterSlide → LayoutSlide → Slide. 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
| Property | Type | Access | Description |
|---|---|---|---|
master_slide | MasterSlide | Read | The master slide that owns this layout. |
layout_type | SlideLayoutType | Read | The predefined layout type (e.g. BLANK, TITLE, TITLE_ONLY). |
shapes | ShapeCollection | Read | Shapes defined on this layout (inherited by slides using it). |
name | str | Read/Write | The name of the layout slide. |
slide_id | int | Read | Numeric identifier extracted from the part name. |
presentation | Presentation | Read | The 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
| Property | Type | Access | Description |
|---|---|---|---|
layout_slides | MasterLayoutSlideCollection | Read | All layout slides belonging to this master. |
shapes | ShapeCollection | Read | Shapes placed on the master (appear on every slide using it). |
name | str | Read/Write | The name of the master slide. |
slide_id | int | Read | Numeric identifier extracted from the part name. |
presentation | Presentation | Read | The parent Presentation object. |
LayoutSlideCollection
LayoutSlideCollection is the base collection class for layout slides. The
GlobalLayoutSlideCollection (returned by prs.layout_slides) extends it.
LayoutSlideCollection Methods
| Method | Signature | Description |
|---|---|---|
get_by_type | (type: SlideLayoutType) -> LayoutSlide | None | Return the first layout matching the given SlideLayoutType. |
__getitem__ | [index: int] -> LayoutSlide | Return layout slide at zero-based index. |
__len__ | () -> int | Number of layouts in the collection. |
__iter__ | N/A | Iterate 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
| Method | Signature | Description |
|---|---|---|
add_clone | (source_master: MasterSlide) -> MasterSlide | Clone a master slide (and all its layouts) from another presentation into this one. |
__getitem__ | [index: int] -> MasterSlide | Return master slide at zero-based index. |
__len__ | () -> int | Number of master slides. |
__iter__ | N/A | Iterate over all master slides. |
SlideLayoutType Enum
Imported from aspose.slides_foss.
| Member | Description |
|---|---|
CUSTOM | Custom layout |
TITLE | Title slide |
BLANK | Blank |
TITLE_ONLY | Title only |
SECTION_HEADER | Section header |
PICTURE_AND_CAPTION | Picture and caption |
TWO_OBJECTS | Two objects |
TEXT | Text |
TABLE | Table |
CHART | Chart |
DIAGRAM | Diagram |
(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}")