Java insert multiple text watermarks to Word document

We have demonstrated how to use Spire.Doc for Java to add text watermark and image watermark to word document. This article will show you how to add WordArt to the Word header to get the multiple watermarks on the Word document:

Insert multiple text watermarks to Word

import com.spire.doc.Document;
import com.spire.doc.FileFormat;
import com.spire.doc.HeaderFooter;
import com.spire.doc.Section;
import com.spire.doc.documents.Paragraph;
import com.spire.doc.documents.ShapeLineStyle;
import com.spire.doc.documents.ShapeType;
import com.spire.doc.fields.ShapeObject;
import java.awt.*;

public class WordWatermark {

    public static void main(String[] args) {

        //Load the sample document
        Document doc = new Document();
        doc.loadFromFile("Sample.docx");
        //Add WordArt shape and set the size
        ShapeObject shape = new ShapeObject(doc, ShapeType.Text_Plain_Text);
        shape.setWidth(60);
        shape.setHeight(20);
        //Set the text, position and sytle for the wordart
        shape.setVerticalPosition(30);
        shape.setHorizontalPosition(20);
        shape.setRotation(315);
        shape.getWordArt().setText("Confidential");
        shape.setFillColor(Color.red);
        shape.setLineStyle(ShapeLineStyle.Single);
        shape.setStrokeColor(new Color(192, 192, 192, 255));
        shape.setStrokeWeight(1);

        Section section;
        HeaderFooter header;
        for (int n = 0; n < doc.getSections().getCount(); n++) {
            section = doc.getSections().get(n);
            //Get the header of section
            header = section.getHeadersFooters().getHeader();
            Paragraph paragraph1;
            for (int i = 0; i < 4; i++) {
                //Add the hearder to the paragraph
                paragraph1 = header.addParagraph();
                for (int j = 0; j < 3; j++) {
                    //copy the word are and add it to many places
                    shape = (ShapeObject) shape.deepClone();
                    shape.setVerticalPosition(50 + 150 * i);
                    shape.setHorizontalPosition(20 + 160 * j);
                    paragraph1.getChildObjects().add(shape);
                }
            }
        }
        //Save the document to file
        doc.saveToFile("Result.docx", FileFormat.Docx_2013);

    }
}

Effective screenshot:

Java insert multiple text watermarks to Word document