Search and Highlight Specific Text in PowerPoint in Java

This article demonstrates how to search and highlight specific text in a PowerPoint document using Spire.Presentation for Java.

import com.spire.presentation.FileFormat;
import com.spire.presentation.IAutoShape;
import com.spire.presentation.Presentation;
import com.spire.presentation.TextHighLightingOptions;

import java.awt.*;

public class SearchAndHighlightText {
    public static void main(String[] args) throws Exception {
        //Create a Presentation instance
        Presentation presentation = new Presentation();
        //Load a PowerPoint document
        presentation.loadFromFile("Input.pptx");

        //Get the first shape on the first slide
        IAutoShape shape = (IAutoShape)presentation.getSlides().get(0).getShapes().get(0);

        //Set highlight options
        TextHighLightingOptions options = new TextHighLightingOptions();
        options.setWholeWordsOnly(true);
        options.setCaseSensitive(true);

        //Highlight text
        shape.getTextFrame().highLightText("Spire", Color.yellow, options);

        //Save the result document
        presentation.saveToFile("HighlightSpecifiedText.pptx", FileFormat.PPTX_2013);
    }
}

Output:

Search and Highlight Specific Text in PowerPoint in Java