Add Watermark

Upload

Maximum file size: 1 MB. Files accepted: doc, docx, txt, rtf.
Click here to browse files.
Source file:
filename
fileerrors

Set text watermark

Text:
Font:
Font Size:
Color:
downloads

Set image watermark

Image:
Click here to browse files
downloads
  • Demo
  • Java
  • C# source
This demo shows you how to add text watermark and image watermark to Word document.
import com.spire.doc.Document;
import com.spire.doc.FileFormat;
import com.spire.doc.PictureWatermark;
import com.spire.doc.TextWatermark;
import com.spire.doc.documents.WatermarkLayout;

import java.awt.*;
import java.io.ByteArrayInputStream;
import java.util.UUID;


public class AddWatermark {

    public void addWaterMark(String docFile, String WaterMarkType, String watermarkText, String imageFile, String resultFilePath) {
        Document document = new Document();
        document.loadFromFile(docFile);
        switch (WaterMarkType) {
            case "Text":
                addTextWatermark(document, watermarkText);
                break;
            case "Image":
                addImageWatermark(document, imageFile);
                break;
        }
        document.saveToFile(resultFilePath, FileFormat.Docx);
    }


    private void addImageWatermark(Document doc, String imageFile){
        PictureWatermark pictureWatermark=new PictureWatermark();
        pictureWatermark.setPicture(imageFile);
        pictureWatermark.setScaling(250);
        pictureWatermark.isWashout(false);
        doc.setWatermark(pictureWatermark);
    }

    private void addTextWatermark(Document doc, String watermarkText){
        TextWatermark textWatermark=new TextWatermark();
        textWatermark.setText(watermarkText);
        textWatermark.setFontSize(14);
        textWatermark.setColor(Color.RED);
        textWatermark.setLayout(WatermarkLayout.Diagonal);
        doc.setWatermark(textWatermark);
    }


}

No Matter How Big or Small Your Project is,
Any technical question related to our product, contact us at support@e-iceblue.com.
Any question related to the purchase of product, contact us at sales@e-iceblue.com.
If you don't find the function you want, please request a free demo from us.