Master Slide
Master slides form the top level of the slide inheritance hierarchy in PowerPoint. A master slide defines common design elements such as backgrounds, logos, and text formatting. Layout slides inherit from master slides, and normal slides inherit from layout slides.
This article demonstrates how to create, modify, and manage master slides using Aspose.Slides for Node.js via Java.
Add a Master Slide
This example shows how to create a new master slide by cloning the default one. It then adds a company name banner to all slides through layout inheritance.
function addMasterSlide() {
let presentation = new aspose.slides.Presentation();
try {
// Clone the default master slide.
let defaultMasterSlide = presentation.getMasters().get_Item(0);
let newMasterSlide = presentation.getMasters().addClone(defaultMasterSlide);
let textBoxFillType = java.newByte(aspose.slides.FillType.NoFill);
// Add a banner with company name to the top of the master slide.
let textBox = newMasterSlide.getShapes().addAutoShape(aspose.slides.ShapeType.Rectangle, 0, 0, 720, 25);
textBox.getTextFrame().setText("Company Name");
textBox.getFillFormat().setFillType(textBoxFillType);
let paragraphFillType = java.newByte(aspose.slides.FillType.Solid);
let paragraphFillColor = java.getStaticFieldValue("java.awt.Color", "BLACK");
let paragraph = textBox.getTextFrame().getParagraphs().get_Item(0);
paragraph.getParagraphFormat().getDefaultPortionFormat().getFillFormat().setFillType(paragraphFillType);
paragraph.getParagraphFormat().getDefaultPortionFormat().getFillFormat().getSolidFillColor().setColor(paragraphFillColor);
// Assign the new master slide to a layout slide.
let layoutSlide = presentation.getLayoutSlides().get_Item(0);
layoutSlide.setMasterSlide(newMasterSlide);
// Assign the layout slide to the first slide in the presentation.
presentation.getSlides().get_Item(0).setLayoutSlide(layoutSlide);
presentation.save("master_slide.pptx", aspose.slides.SaveFormat.Pptx);
} finally {
presentation.dispose();
}
}
💡 Note 1: Master slides provide a way to apply consistent branding or shared design elements across all slides. Any changes made to the master will automatically reflect on dependent layout and normal slides.
💡 Note 2: Any shapes or formatting added to a master slide are inherited by layout slides and, in turn, all normal slides using those layouts. The image below illustrates how a text box added on a master slide is automatically rendered on the final slide.

Access a Master Slide
You can access master slides using the presentation master collection. Here’s how to retrieve and work with them:
function accessMasterSlide() {
let presentation = new aspose.slides.Presentation("master_slide.pptx");
try {
let firstMasterSlide = presentation.getMasters().get_Item(0);
// Change the background type.
let backgroundType = java.newByte(aspose.slides.BackgroundType.OwnBackground);
firstMasterSlide.getBackground().setType(backgroundType);
} finally {
presentation.dispose();
}
}
Remove a Master Slide
Master slides can be removed either by index or by reference.
function removeMasterSlide() {
let presentation = new aspose.slides.Presentation("master_slide.pptx");
try {
// Remove a master slide by index.
presentation.getMasters().removeAt(0);
// Remove a master slide by reference.
let firstMasterSlide = presentation.getMasters().get_Item(0);
presentation.getMasters().remove(firstMasterSlide);
presentation.save("master_slide_removed.pptx", aspose.slides.SaveFormat.Pptx);
} finally {
presentation.dispose();
}
}
Remove Unused Master Slides
Some presentations contain master slides that are not in use. Removing these slides can help reduce file size.
function removeUnusedMasterSlides() {
let presentation = new aspose.slides.Presentation("master_slide.pptx");
try {
// Remove all unused master slides (even those marked as Preserve).
presentation.getMasters().removeUnused(true);
presentation.save("unused_master_slides_removed.pptx", aspose.slides.SaveFormat.Pptx);
} finally {
presentation.dispose();
}
}