Slide Master

What is a Slide Master in PowerPoint

A Slide Master is a slide template that defines the layout, styles, theme, fonts, background, and other properties for slides in a presentation. If you want to create a presentation (or series of presentations) with the same style and template for your company, you can use a slide master.

A Slide Master is useful because it allows you to set and change the look of all presentation slides at once. Aspose.Slides supports the Slide Master mechanism from PowerPoint.

VBA also allows you to manipulate a Slide Master and execute the same operations supported in PowerPoint: change backgrounds, add shapes, customize the layout, etc. Aspose.Slides provides flexible mechanisms to allow you to use Slide Masters and perform basic tasks with them.

These are basic Slide Master operations:

  • Create or Slide Master.
  • Apply Slides Master to presentation slides.
  • Change Slide Master background.
  • Add an image, placeholder, Smart Art, etc. to Slide Master.

These are more advanced operations involving Slide Master:

  • Compare Slide Masters.
  • Merge Slide Masters.
  • Apply several Slide Masters.
  • Copy slide with Slide Master to another presentation.
  • Find out duplicate Slide Masters in presentations.
  • Set Slide Master as the presentation default view.

How is Slide Master applied

Before you work with a slide master, you may want to understand how they are used in presentations and applied to slides.

  • Every presentation has at least one Slide Master by default.
  • A presentation can contain several Slide Masters. You can add several Slide Masters and use them to style different parts of a presentation in different ways.

In Aspose.Slides, a Slide Master is represented by IMasterSlide type.

Aspose.Slides' Presentation object contains the masters list of IMasterSlideCollection type, which contains a list of all master slides that are defined in a presentation.

Besides CRUD operations, the IMasterSlideCollection interface contains these useful methods: add_clone and insert_clone methods. Those methods are inherited from the basic slide cloning function. But when dealing with Slide Masters, those methods allow you to implement complicated setups.

When a new slide is added to a presentation, a Slide Master is applied to it automatically. The Slide Master of the previous slide is selected by default.

Note: Presentation slides are stored in Slides list, and every new slide is added to the end of the collection by default. If a presentation contains a single Slide Master, that slide master is selected for all new slides. This is the reason you do not have to define the Slide Master for every new slide you create.

The principle is the same for PowerPoint and Aspose.Slides. For example, in PowerPoint, when you add a new presentation, you can just press on the bottom line under the last slide and then a new slide (with the last presentation’s Slide Master) will be created:

todo:image_alt_text

In Aspose.Slides, you can perform the equivalent task with the add_clone(ISlide) method under the Presentation class.

Slide Master in Slides hierarchy

Using Slide Layouts with Slide Master allows for maximum flexibility. A Slide Layout allows you to set all the same styles as Slide Master (background, fonts, shapes, etc.). However, when several Slide Layouts are combined on a Slide Master, a new style is created. When you apply a Slide Layout to a single slide, you can change its style from the one applied by the Slide Master.

Slide Master outranks all setups items: Slide Master -> Slide Layout -> Slide:

todo:image_alt_text

Each IMasterSlide object has a LayoutSlides property with a list of Slide Layouts. A Slide type has a LayoutSlide property with a link on a Slide Layout applied to the slide. The interaction between a slide and Slide Master occurs through a Slide Layout.

What A Slide Master Comprises

To understand how a Slide Master can be changed, you need to know its constituents. These are MasterSlide core properties.

  • background get/set slide background.
  • body_style get/set text styles of the slide’s body.
  • shapes get/set all the shapes of the Slide Master (placeholders, picture frames, etc).
  • controls - get/set ActiveX controls.
  • theme_manager - get theme manager.
  • header_footer_manager - get header and footer manager.

Slide Master methods:

  • get_depending_slides() - get all Slides depending on the Slide Master.
  • apply_external_theme_to_depending_slides(fname) - allows you to create a new Slide Master based on the current Slide Master and a new theme. The new Slide Master will then be applied to all dependent slides.

Get Slide Master

In PowerPoint, Slide Master can be accessed from the View -> Slide Master menu:

todo:image_alt_text

Using Aspose.Slides, you can access a Slide Master this way:

import aspose.slides as slides

with slides.Presentation() as pres:
    # Gives access to the Presentation's master slide
    masterSlide = pres.masters[0]

The IMasterSlide interface represents a Slide Master. The masters property (related to IMasterSlideCollection type) contains a list of all Slide Masters that are defined in the presentation. 

Add Image to Slide Master

When you add an image to a Slide Master, that image will appear on all slides dependent on that slide master.

For example, you can place your company’s logo and a few images on the Slide Master and then switch back to slide editing mode. You should see the image on every slide.

todo:image_alt_text

You can add images to a slide master with Aspose.Slides:

import aspose.slides as slides

with slides.Presentation() as pres:
    image = pres.images.add_image(open("image.png", "rb").read())
    pres.masters[0].shapes.add_picture_frame(slides.ShapeType.RECTANGLE, 10, 10, 100, 100, image)

    pres.save("pres.pptx", slides.export.SaveFormat.PPTX)

Add Placeholder to Slide Master

These text fields are standard placeholders on a Slide Master:

  • Click to edit Master title style

  • Edit Master text styles

  • Second level

  • Third level

    They also appear on the slides based on Slide Master. You can edit those placeholders on a Slide Master and the changes are applied automatically to the slides.

In PowerPoint, you can add a placeholder through the Slide Master -> Insert Placeholder path:

todo:image_alt_text

Let’s examine a more complicated example for placeholders with Aspose.Slides. Consider a slide with placeholders templated from the Slide Master:

todo:image_alt_text

We want to change the Title and Subtitle formatting on the Slide Master this way:

todo:image_alt_text

First, we retrieve the title placeholder content from the Slide Master object and then use thePlaceHolder.FillFormat field:

# Gets the reference to the master's title placeholder
titlePlaceholder = masterSlide.shapes[0]

# Sets format fill as gradient fill
titlePlaceholder.fill_format.fill_type = slides.FillType.GRADIENT
titlePlaceholder.fill_format.gradient_format.gradient_stops.add(0, draw.Color.red)
titlePlaceholder.fill_format.gradient_format.gradient_stops.add(50, draw.Color.green)
titlePlaceholder.fill_format.gradient_format.gradient_stops.add(100, draw.Color.blue)

The title style and formatting will change for all slides based on the slide master:

todo:image_alt_text

Change Background on Slide Master

When you change a master slide’s background color, all the normal slides in the presentation will get the new color. This Python code demonstrates the operation:

masterSlide.background.type = slides.BackgroundType.OWN_BACKGROUND
masterSlide.background.fill_format.fill_type = slides.FillType.SOLID
masterSlide.background.fill_format.solid_fill_color.color = draw.Color.gray

Clone Slide Master to Another Presentation

To clone a Slide Master to another presentation, call the add_clone(source_slide, dest_master, allow_clone_missing_layout) method from the destination presentation alongside a Slide Master passed into it. This Python code shows you how to clone a Slide Master to another presentation:

# Adds a new master slide 
pres1MasterSlide = pres.masters.add_clone(masterSlide)

Add Multiple Slide Masters to Presentation

Aspose.Slides allows you to add several Slide Masters and Slide Layouts to any given presentation. This allows you to set up styles, layouts, and formatting options for presentation slides in many ways.

In PowerPoint, you can add new Slide Masters and Layouts (from the “Slide Master menu) this way:

todo:image_alt_text

Using Aspose.Slides, you can add a new Slide Master by calling the add_clone method:

# Adds a new master slide
secondMasterSlide = pres.masters.add_clone(masterSlide)

Compare Slide Masters

A Master Slide implements the IBaseSlide interface containing the equals(slide) method, which can then be used to compare slides. It returns true for Master Slides identical in structure and static content.

Two Master Slides are equal if their shapes, styles, texts, animation and other settings, etc are equal. The comparison does not take unique identifier values (e.g. SlideId) and dynamic content (e.g. current date value in Date Placeholder) into account.

Set Slide Master as Presentation Default View

Aspose.Slides allows you to set a Slide Master as the default view for a presentation. The default view is what you see first when you open a presentation.

This code shows you how to set a Slide Master as a presentation’s default view in Python:

import aspose.slides as slides

# Instantiates a Presentation class that represents the presentation file
with slides.Presentation() as presentation:
    # Sets the Default View as SlideMasterView
    presentation.view_properties.last_view = slides.ViewType.SLIDE_MASTER_VIEW

    # Saves the presentation
    presentation.save("PresView.pptx", slides.export.SaveFormat.PPTX)

Remove Unused Master Slide

Aspose.Slides provides the remove_unused_master_slides method (from the Compress class) to allow you to delete unwanted and unused master slides. This Python code shows you how to remove a master slide from a PowerPoint presentation:

import aspose.slides as slides

with slides.Presentation("pres.pptx") as pres:
    slides.lowcode.Compress.remove_unused_master_slides(pres)
    pres.save("pres-out.pptx", slides.export.SaveFormat.PPTX)