Wednesday, 04 December 2019 03:42

Highlight Text in PowerPoint in C#

Written by  support iceblue
Rate this item
(0 votes)

This article demonstrates how to highlight the specific text within a PowerPoint document by using Spire.Presentation for .NET.

using Spire.Presentation;
using System.Drawing;

namespace HighlightTextInPPT
{
    class Program
    {
        static void Main(string[] args)
        {
            //Load the sample PowerPoint file
            Presentation presentation = new Presentation();
            presentation.LoadFromFile(@"C:\Users\Administrator\Desktop\sample.pptx");

            //Loop through the slides
            for (int i = 0; i < presentation.Slides.Count; i++)
            {
                //Get the specific slide
                ISlide slide = presentation.Slides[i];

                //Loop through the shapes
                for (int j = 0; j < slide.Shapes.Count; j++)
                {
                    if (slide.Shapes[j] is IAutoShape)
                    {
                        //Get the specific shape
                        IAutoShape shape = slide.Shapes[j] as IAutoShape;

                        //Initialize an object of TextHighLightingOptions
                        TextHighLightingOptions options = new TextHighLightingOptions();
                        options.CaseSensitive = true;
                        options.WholeWordsOnly = true;

                        //Highligh the specific text within the shape with color
                        shape.TextFrame.HighLightText("Spire.Presentation", Color.LightYellow, options);
                    }
                   
                }
            }

            //Save to file
            presentation.SaveToFile("Highlight Text.pptx", FileFormat.Pptx2013);
        }
    }
}

Highlight Text in PowerPoint in C#

Additional Info

  • tutorial_title:
Last modified on Wednesday, 04 December 2019 03:52