Set Slide Background in PowerPoint Presentations using Java

In this article, you will learn how to dynamically set the background of slides in PowerPoint presentations using Java. More precisely, the article will cover how to set the background of normal slides as well as the master slide.

Java API to Set Slide Background in PowerPoint

To set the background of slides in PPTX/PPT presentations, we will use Aspose.Slides for Java. The API lets you create, manipulate and convert PowerPoint and OpenOffice presentations from within the Java applications. You can either download the API or install it in your Maven-based applications using the following configurations.

<repository>
    <id>AsposeJavaAPI</id>
    <name>Aspose Java API</name>
    <url>http://repository.aspose.com/repo/</url>
</repository>
<dependency>
    <groupId>com.aspose</groupId>
    <artifactId>aspose-slides</artifactId>
    <version>21.8</version>
    <classifier>jdk16</classifier>
</dependency>

Set Background Color of Normal Slides in Java

The following are the steps to set the background color of the normal slides in a PowerPoint presentation using Java.

  • First, load the PowerPoint presentation using Presentation class.
  • Then, set the background of the desired slide by specifying its index, e.g. background type, color, fill type, etc.
  • Finally, save the updated presentation using Presentation.save(String, SaveFormat) method.

The following code sample shows how to set the background of a slide in a PowerPoint presentation.

The screenshot of the slide before setting the background is given below.

PowerPoint Presentation

The following is the PowerPoint slide after setting the background.

Set Background of Slide in C#

Set Background Color of Master Slide in Java

You can also set the background of the master slide that will affect all the slides in the presentation. The following are the steps to change the background color of the master slide.

  • First, load the PowerPoint presentation using Presentation class.
  • Then, set the background of the master slide, e.g. background type, color, fill type, etc.
  • Finally, save the updated presentation using Presentation.save(String, SaveFormat) method.

The following code sample shows how to change the background of the master slide in PowerPoint.

Set Gradient Background Color of Slides

The following are the steps to set a gradient background color of the slides in a PowerPoint presentation.

The following code sample shows how to set the gradient background color of the slides in PowerPoint.

The following screenshot shows the gradient background of the slide.

Set Gradient Background of Slide in C#

Set Image as Slide Background using Java

The following are the steps to set an image as a slide background using Java.

The following code sample shows how to set an image as the background of slides in a PowerPoint presentation.

Get a Free API License

You can use Aspose.Slides for Java without evaluation limitations by requesting a temporary license.

Conclusion

In this article, you have learned how to set the background of slides in PowerPoint PPTX or PPT using Java. Furthermore, you have seen how to set gradient or image background of the PowerPoint presentations. You can visit the documentation to explore other features of Aspose.Slides for Java. Also, you can feel free to let us know about your queries via our forum.

See Also