Microsoft PowerPoint provides a wide variety of themes that you can use in your PowerPoint presentations. These themes improve the look and feel of the presentations and make them perfect for modern and sophisticated pitches. You can also apply themes to PowerPoint files dynamically within your C++ applications. To that end, this article will teach you how to apply themes in PowerPoint presentations programmatically using C++.
- C++ API for Applying Theme in PowerPoint Presentations
- Apply Theme to PowerPoint Presentations using C++
C++ API for Applying Theme in PowerPoint Presentations
Aspose.Slides for C++ is a C++ API for working with PowerPoint files. It enables you to create, read and update PPT and PPTX files without needing additional software. Furthermore, the API allows you to apply themes to PowerPoint presentations. You can either install the API through NuGet or download it directly from the Downloads section.
PM> Install-Package Aspose.Slides.Cpp
Apply Theme to PowerPoint Presentations using C++
A PowerPoint theme is a set of colors, font family, font size, background style, etc., that can be applied to different elements. In the following sections, we will explore how to set the theme color, font, and background style in PowePoint presentations.
Set Theme Color in PowerPoint Presentation using C++
The following are the steps to set the theme color for a shape in a PowerPoint presentation.
- Create an instance of the Presentation class to represent a new PowerPoint file.
- Add a shape using the AddAutoShape(ShapeType shapeType, float x, float y, float width, float height) method.
- Set the fill type and scheme color.
- Save the presentation using the Presentation->Save(System::String fname, Export::SaveFormat format) method.
The following sample code shows how to set the theme color for a shape in a PowerPoint presentation using C++.
Set Theme Font in PowerPoint Presentation using C++
Similar to Microsoft PowerPoint, Aspose.Slides for C++ API provides the following identifiers to set the font from the font scheme.
- “+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 a text element and assign the Latin font to it.
- Create an instance of the Presentation class to represent a new PowerPoint file.
- Add a shape using the AddAutoShape(ShapeType shapeType, float x, float y, float width, float height) method.
- Create a Paragraph and add a Portion into it.
- Set the font using the Portion->get_PortionFormat()->set_LatinFont(System::SharedPtr<IFontData> value) method.
- Save the presentation using the Presentation->Save(System::String fname, Export::SaveFormat format) method.
The following sample code shows how to set the theme font in a PowerPoint presentation using C++.
Change Theme Background Style in PowerPoint Presentation using C++
The following are the steps to set the theme background style in a PowerPoint presentation.
- Create an instance of the Presentation class to represent a new PowerPoint file.
- Set the background style using the Presentation->get_Masters()->idx_get(0)->get_Background()->set_StyleIndex(uint16_t value) method.
- Save the presentation using the Presentation->Save(System::String fname, Export::SaveFormat format) method.
The following sample code demonstrates how to set the theme background style in a PowerPoint presentation using C++.
Get a Free License
In order to try the API without evaluation limitations, you can request a free temporary license.
Conclusion
In this article, you have learned how to apply themes in PowerPoint presentations using C++. Specifically, you have learned how to set the theme color, font, and background style of PowerPoint presentations. Aspose.Slides for C++ is a robust API that provides many additional features for working with PPTX/PPT files. You can explore the API in detail by visiting the official documentation. In case of any queries, please feel free to reach us at our free support forum.