PowerPoint supports a range of themes that you can use in the presentations. In addition, you can define your own themes as per your requirements. In this article, you will learn how to use themes in PowerPoint presentations dynamically, Particularly, the article will cover how to apply themes in the PowerPoint presentations programmatically using Java.
- Java API to Apply Themes in PowerPoint Presentations
- Apply Theme to a PowerPoint Presentation in Java
Java API to Apply Themes in PowerPoint Presentations
In order to apply themes in PowerPoint presentations, we will use Aspose.Slides for Java. It is a powerful and feature-rich API to create and manipulate presentations from within Java applications. You can either download the API or install it using the following Maven 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>
Apply Theme in a PowerPoint Presentation using Java
A PowerPoint theme represents a set of colors, font size, font family, background style, etc. that you can apply to different elements. In the below sections, we will explicitly cover how to set theme color, font, and background in a PowerPoint presentation.
Set Theme Color in PowerPoint Presentation using Java
The following are the steps to set theme color for a shape in a PowerPoint presentation using Java.
- First, load a presentation or create a new one using Presentation class.
- Then, add a new shape to the presentation using addAutoShape() method.
- Set fill type using IAutoShape.getFillFormat().setFillType() method.
- Set color using IAutoShape.getFillFormat().getSolidFillColor().setSchemeColor() method.
- Finally, save the presentation using Presentation.save(String, SaveFormat) method.
The following code sample shows how to set a theme color in a PowerPoint presentation using Java.
Set Theme Font in the Presentation using Java
Aspose.Slides provides special identifiers to set font from the font scheme. These identifiers are as follows:
- “+mn-lt“: Body Font Latin (Minor Latin Font)
- “+mj-lt“: Heading Font Latin (Major Latin Font)
- “+mn-ea“: Body Font East Asian (Minor East Asian Font)
- “+mj-ea“: Body Font East Asian (Minor East Asian Font)
The following are the steps to create an element with the text and assign the Latin font from the font scheme.
- First, load a presentation or create a new one using Presentation class.
- Then, add a new shape to the presentation using addAutoShape() method.
- Create a new Paragraph and add a Portion into it.
- Set Latin font using Portion.getPortionFormat().setLatinFont() method.
- Finally, save the presentation using Presentation.save(String, SaveFormat) method.
The following code sample shows how to set theme font in a PowerPoint presentation using Java.
Change Theme Background Style in Presentation using Java
The presentation themes also contain the background styles that you can set in a PowerPoint presentation. The following are the steps to perform this operation.
- First, load a presentation or create a new one using Presentation class.
- Then, set the background style by assigning its index using Presentation.getMasters().get_Item(index).getBackground().setStyleIndex() method.
- Finally, save the presentation using Presentation.save(String, SaveFormat) method.
The following code sample shows how to set theme background style in a 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 apply theme color, font, and background style in PowerPoint presentations using Java. You can simply install the API and integrate the provided code into your applications. In addition, you can visit the documentation to explore more about Aspose.Slides for Java. Also, you can post your queries to our forum.
See Also
- Add Watermark to PowerPoint Slides using Java
- Extract Text from PowerPoint Files using Java
- Add, Connect, Remove, or Clone PowerPoint Shapes in Java
- Convert PowerPoint PPTX/PPT to PNG Images in Java
- Generate Thumbnails for PowerPoint PPTX or PPT using Java