StrikeThrough Text using Java

Probably you have some content that is no more valid. Let’s cross it out. Crossing out is one of the ways, used to highlight the invalid content within the documents. In order to automate the cross-out within the applications, this article shows how to strikethrough text in documents in Java.

The following topics are discussed in this article.

Java API to Strikethrough Text

GroupDocs.Annotation showcases Java API that supports various annotations that can be applied to multiple documents and images. We will use it in the examples of this article to cross out the selected text within the documents.

You can download the JAR file from the downloads section or use the latest repository and dependency Maven configurations within your Java applications.

<repository>
	<id>GroupDocsJavaAPI</id>
	<name>GroupDocs Java API</name>
	<url>http://repository.groupdocs.com/repo/</url>
</repository>
<dependency>
        <groupId>com.groupdocs</groupId>
        <artifactId>groupdocs-annotation</artifactId>
        <version>21.7.2</version> 
</dependency>

How to Strikethrough Text in Documents using Java

Let’s cross out the area of the document that is not valid anymore. The following steps allow you to strike through the text within documents in Java.

  • Load the source document (PDF, Word, etc) using Annotator class.
  • Create and define the strikethrough annotation using StrikeoutAnnotation class.
    • Set the line color for strikeout.
    • Set opacity, document page number.
    • Define Coordinates and other properties.
  • Add the prepared strikeout annotation to the annotator using add() method.
  • Finally, save the annotated document using the save() method.

Similarly, you can annotate Word documents, spreadsheets, presentations, PDF documents, web pages, email messages, and many other documents.

The following Java code example strikes out the selected text in a PDF document.

Get a Free API License

You can use GroupDocs.Annotation for Java for free by getting a temporary license.

Conclusion

To conclude, we discussed programmatically adding the cross-out annotation to documents within Java applications. Additionally, you can strike out the text within PDF files, spreadsheets, presentations, and Word documents. Likewise, you can also use other annotations as you like.

Learn more about GroupDocs.Annotation for Java from its documentation. Try building your own annotator for the supported document formats. Feel free to contact us for queries via the forum.

See Also