Java add text watermark and image watermark to word document

This section will demonstrate how to use Spire.Doc for Java to add text watermark and image watermark to Word document in Java applications.

Add text watermark

import com.spire.doc.*;
import com.spire.doc.documents.WatermarkLayout;
import java.awt.*;

public class WordTextWatermark {
    public static void main(String[] args) {

        Document document = new Document();
        document.loadFromFile("Sample.docx");

        insertTextWatermark(document.getSections().get(0));

        document.saveToFile("out/result.docx",FileFormat.Docx );
    }
    private static void insertTextWatermark(Section section) {
        TextWatermark txtWatermark = new TextWatermark();
        txtWatermark.setText("Confidential");
        txtWatermark.setFontSize(40);
        txtWatermark.setColor(Color.red);
        txtWatermark.setLayout(WatermarkLayout.Diagonal);
        section.getDocument().setWatermark(txtWatermark);
    }

}

Effective screenshot of text watermark on word:

Java add text watermark and image watermark to word document

Add image watermark

import com.spire.doc.*;


public class WordImageWatermark {
    public static void main(String[] args)  throws Exception{

        Document document = new Document();
        document.loadFromFile("Sample.docx");

         PictureWatermark picture = new PictureWatermark();
         picture.setPicture("logo.png");
         picture.setScaling(5);
         picture.isWashout(false);
         document.setWatermark(picture);

         document.saveToFile("out/result2.docx",FileFormat.Docx );
    }
}

Effective screenshot of image watermark on word:

Java add text watermark and image watermark to word document