Java/ Search and Highlight Specific Text in PowerPoint

It’s easy for us to search the specific text and highlight them with background color in a PowerPoint documents. This article will introduce how to realize the same function using Java. (Free API: Free Spire.Presentation for Java)

Installation (2 Methods)
● Download the Java API (Free Spire.Presentation for Java) and unzip it, then add the Spire.Presentation.jar file to your project as dependency.

● Directly add the jar dependency to your maven project by adding the following configurations to the pom.xml.

<repositories>
<repository>
<id>com.e-iceblue</id>
<name>e-iceblue</name>
<url>http://repo.e-iceblue.com/nexus/content/groups/public/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>e-iceblue</groupId>
<artifactId>spire.presentation.free</artifactId>
<version>3.9.0</version>
</dependency>
</dependencies>

Relevant code snippet:

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("test2.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("Auden", Color.BLUE, options);

//Saimport 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("test2.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("Auden", Color.BLUE, options);

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

Result:

Sharing Java Code