DEV Community

CodeSharing
CodeSharing

Posted on

[Java] Add WordArt to Word Document

Compared with ordinary text, WordArt is more creative and decorative, it is often used in the beautifully designed magazines or posters. In this article, I will introduce how to add WordArt in a Word document by using Free Spire.Doc for Java.

Installation
Method 1: Download the Free Spire.Doc for Java and unzip it. Then add the Spire.Doc.jar file to your Java application as dependency.

Method 2: You can also 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>http://repo.e-iceblue.com/nexus/content/groups/public/</url>
   </repository>
</repositories>
<dependencies>
   <dependency>
      <groupId>e-iceblue</groupId>
      <artifactId>spire.doc.free</artifactId>
      <version>2.7.3</version>
   </dependency>
</dependencies>
Enter fullscreen mode Exit fullscreen mode

Add WordArt

import com.spire.doc.*;
import com.spire.doc.documents.*;
import com.spire.doc.fields.ShapeObject;
import java.awt.*;


public class WordArt{
    public static void main(String[] args) throws Exception {
        //Create a Word document.
        Document doc = new Document();

        //Add a section
        Section section = doc.addSection();

        //Add a paragraph.
        Paragraph paragraph = section.addParagraph();

        //Add a shape
        ShapeObject shape = paragraph.appendShape(250, 70, ShapeType.Text_Wave_4);

        //Set the position of the shape
        shape.setVerticalPosition(80);
        shape.setHorizontalPosition(100);

        //Set the text of WordArt
        shape.getWordArt().setText("Thanks for reading");

        //Set the fill color
        shape.setFillColor(Color.CYAN);

        //Set the border color of the text
        shape.setStrokeColor(Color.BLACK);

        //Save the document
        doc.saveToFile("WordArt.docx", FileFormat.Docx_2013);
    }
}
Enter fullscreen mode Exit fullscreen mode

Alt Text

Top comments (0)