How to Change Slide Master in PowerPoint Presentations in Java

How to Change Slide Master in PowerPoint Presentations in Java

PowerPoint (PPT, PPTX) presentation uses the slide master to modify all existing slides and their layouts in your presentation. You can add multiple slide masters to your PowerPoint presentations, depending on how you want to present your data. In this blog post, we will implement how to change slide master in PowerPoint presentation in Java. Additionally, we will write a code sample to copy slide master to another presentation.

This article will cover the points given below:

Java API to change slide master in PowerPoint presentations

To change slide master in PowerPoint presentations, we will use Java PowerPoint API, which consists of many remarkable and rich features to manipulate PowerPoint presentations programmatically. This Java library can be installed directly using the Maven configurations as given below:

 <repository>
	<id>ConholdateJavaAPI</id>
	<name>Conholdate Java API</name>
	<url>https://releases.conholdate.com/java/repo</url>
</repository>        
<dependency>
	<groupId>com.conholdate</groupId>
	<artifactId>conholdate-total</artifactId>
	<version>23.6</version>
	<type>pom</type>
</dependency>

For configurations about other Java frameworks, please visit releases.conholdate.com.

How to change slide master’s background of a presentation: Java Tutorial

Please be aware that slide master is not an actual slide in a PowerPoint presentation. It just holds the information about layouts and formatting elements (such as background, fonts, shapes, placeholders, ActiveX controls, etc) of all slides.

Suppose we have a PowerPoint presentation (PPT or PPTX) in which a slide master has applied to all slides.

Change slide master's background

By considering the presentation file above, Let’s change the background element of its slide master using Java PowerPoint presentation management API.

Follow the steps given below:

  1. Initialize object of Presentation class with source PowerPoint presentation’s path.
  2. Obtain object of IMasterSlide using IMasterSlideCollection.get_Item(int index) method.
  3. Set background color of IMasterSlide using IBackground.setType(byte value), IFillFormat.setFillType(byte value) and IColorFormat.setColor(Color value) methods.
  4. Call Presentation.save(String fname, int format) method and pass it output path and SaveFormat value. The following code sample shows how to change the slide master’s background of a presentation in Java.

As a result, you will see the changed background color of all slides of the PowerPoint presentation.

Change slide master's background in Java

Java: Copy slide master of a PPTX to another presentation

The Java presentation management API facilitates you to copy the slide master of a presentation (PPTX or PPT) to another presentation.

  1. Initialize objects of Presentation class with the paths of source and destination presentations.
  2. Obtain object of IMasterSlide object of source presentation using IMasterSlideCollection.get_Item(int index) method.
  3. Copy obtained IMasterSlide object to destination presentation using addClone() method.
  4. Call Presentation.save(String fname, int format) method and pass it output path and SaveFormat value.

The code sample below demonstrates how to get the list of all changes.

Get a Free License

You can get a free temporary license to try the API without evaluation limitations.

Conclusion

To sum up, we learned how to change slide master in PowerPoint presentation in Java using a Powerpoint manipulation and management API. Specifically, we wrote a code sample to change the background of a presentation’s slide master and learned how to copy a slide master of a PPTX or PPT to another presentation using Java programming language.

You may visit the documentation to explore other features.

Ask a question

You can let us know your questions or queries on our forum.

See Also