Apply Emphasis Marks in Word in Java
In Word, you can emphasize some important contents by adding specific symbols such as underline, overline and highlight colors. In addition, you can also use emphasis mark to make the content more noticable. This article will share how to programmatically apply emphasis marks to text in Word using Free Spire.Doc for Java.
Import Dependency
Method 1: Download the free library and unzip it. Then add the Spire.Doc.jar file to your Java application as dependency.
Method 2: Directly add the jar dependency to maven project by adding the following configurations to the pom.xml.
<repositories>
<repository>
<id>com.e-iceblue</id>
<name>e-iceblue</name>
<url>https://repo.e-iceblue.com/nexus/content/groups/public/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>e-iceblue</groupId>
<artifactId>spire.doc.free</artifactId>
<version>5.2.0</version>
</dependency>
</dependencies>
Sample Code
The emphasis mark looks like dots under each of the characters. With Free Spire.Doc for Java, you can first find specified text using Document.findAllString() method and then apply emphasis mark to the found text using TextRange.getCharacterFormat().setEmphasisMark() method. Below is the complete sample code.
import com.spire.doc.*;
import com.spire.doc.documents.*;
import com.spire.doc.fields.shape.*;
public class applyEmphasisMark {
public static void main(String[] args) {
//Create word document
Document document = new Document();
//Load the document from disk
document.loadFromFile("test.docx");
//Find text to emphasize
TextSelection[] textSelections = document.findAllString("Ancient Olympics", false, true);
//Set emphasis mark to the found text
for (TextSelection selection : textSelections) {
selection.getAsOneRange().getCharacterFormat().setEmphasisMark(Emphasis.Dot);
}
//Save the file
document.saveToFile("EmphasisMark.docx", FileFormat.Docx);
}
}