When creating a PowerPoint presentation, you may want to ensure that some important content in your presentation grabs the audience’s attention. A great way to make the content more prominent and noticeable is to highlight it with a bright color. This article will demonstrate how to highlight text in a PowerPoint presentation in C# and VB.NET using Spire.Presentation for .NET.
Install Spire.Presentation for .NET
To begin with, you need to add the DLL files included in the Spire.Presentation for.NET package as references in your .NET project. The DLL files can be either downloaded from this link or installed via NuGet.
PM> Install-Package Spire.Presentation
Highlight Text in PowerPoint in C# and VB.NET
The following are the steps to highlight specific text in a PowerPoint document:
- Initialize an instance of Presentation class.
- Load a PowerPoint presentation using Presentation.LoadFromFile() method.
- Loop through the slides in the presentation and the shapes on each slide.
- Check if the current shape is of IAutoShape type.
- If the result is true, typecast it to IAutoShape.
- Initialize an instance of TextHighLightingOptions class, and set the text highlighting options such as whole words only and case sensitive through TextHighLightingOptions.WholeWordsOnly and TextHighLightingOptions.CaseSensitive properties.
- Highlight a specific text in the shape using IAutoShape.TextFrame.HighLightText() method.
- Save the result file using Presentation.SaveToFile() method.
- C#
- VB.NET
using Spire.Presentation; using System.Drawing; namespace HighlightTextInPPT { class Program { static void Main(string[] args) { //Create an instance of Presentation class Presentation presentation = new Presentation(); //Load a PowerPoint file presentation.LoadFromFile(@"Sample1.pptx"); //Loop through all slides for (int i = 0; i < presentation.Slides.Count; i++) { //Get the current slide ISlide slide = presentation.Slides[i]; //Loop through the shapes on the slide for (int j = 0; j < slide.Shapes.Count; j++) { //Check if the current shape is of IAutoShape type if (slide.Shapes[j] is IAutoShape) { //Typecast the shape to IAutoShape IAutoShape shape = slide.Shapes[j] as IAutoShape; //Create an instance of TextHighLightingOptions class TextHighLightingOptions options = new TextHighLightingOptions(); //Set text highlighting options options.CaseSensitive = true; options.WholeWordsOnly = true; //Highlight specific text within the shape with color shape.TextFrame.HighLightText("Spire.Presentation", Color.LightYellow, options); } } } //Save the result file presentation.SaveToFile("HighlightText.pptx", FileFormat.Pptx2013); } } }
Apply for a Temporary License
If you'd like to remove the evaluation message from the generated documents, or to get rid of the function limitations, please request a 30-day trial license for yourself.