PowerPoint provides a wide range of themes that you can apply in the presentations. In addition, you can define your custom themes as per your requirements. In this article, you will learn how to work with themes of PowerPoint presentations dynamically, Particularly, the article will cover how to apply themes in the PowerPoint presentations programmatically using C#.
C# API to Apply Themes in PowerPoint PPT
To apply themes in PowerPoint presentations, we will use Aspose.Slides for .NET. It is a powerful and feature-rich API to create and manipulate presentations from within .NET applications. You can either download the API or install it using NuGet.
PM> Install-Package Aspose.Slides.NET
Apply Theme in a PowerPoint Presentation in C#
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.
Apply PowerPoint Theme in C# - Set Theme Color
The following are the steps to set a theme color for a shape in a PowerPoint presentation using C#.
- First, load a presentation or create a new one using Presentation class.
- Then, add a new shape to the presentation using AddAutoShape() method.
- Set IAutoShape.FillFormat.FillType property.
- Set IAutoShape.FillFormat.SolidFillColor.SchemeColor property to desired color.
- 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 in C#.
Set PowerPoint PPT Theme Font in C#
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.PortionFormat.LatinFont property.
- Finally, save the presentation using Presentation.Save(String, SaveFormat) method.
The following code sample shows how to set the theme font in a PowerPoint presentation using C#.
Change PPT Theme Background Style in C#
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 to Presentation.Masters[0].Background.StyleIndex property.
- Finally, save the presentation using Presentation.Save(String, SaveFormat) method.
The following code sample shows how to set the theme background style in a presentation.
Work with PowerPoint Themes in C# - Get a Free License
You can manipulate themes in PowerPoint presentations 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 C#. Moreover, you can install the API and integrate the provided code or customize it as per your requirements. In addition, you can visit the documentation to explore more about Aspose.Slides for .NET. Also, you can post your queries to our forum.