Watermark

Inheritance: java.lang.Object

public class Watermark

Represents class to work with document watermark.

To learn more, visit the Working with Watermark documentation article.

Methods

MethodDescription
getType()Gets the watermark type.
remove()Removes the watermark.
setImage(BufferedImage image)Adds Image watermark into the document.
setImage(BufferedImage image, ImageWatermarkOptions options)Adds Image watermark into the document.
setImage(String imagePath, ImageWatermarkOptions options)Adds Image watermark into the document.
setText(String text)Adds Text watermark into the document.
setText(String text, TextWatermarkOptions options)Adds Text watermark into the document.

getType()

public int getType()

Gets the watermark type.

Returns: int - The watermark type. The returned value is one of WatermarkType constants.

remove()

public void remove()

Removes the watermark.

Examples:

Shows how to create a text watermark.


 Document doc = new Document();

 // Add a plain text watermark.
 doc.getWatermark().setText("Aspose Watermark");

 // If we wish to edit the text formatting using it as a watermark,
 // we can do so by passing a TextWatermarkOptions object when creating the watermark.
 TextWatermarkOptions textWatermarkOptions = new TextWatermarkOptions();
 textWatermarkOptions.setFontFamily("Arial");
 textWatermarkOptions.setFontSize(36f);
 textWatermarkOptions.setColor(Color.BLACK);
 textWatermarkOptions.setLayout(WatermarkLayout.DIAGONAL);
 textWatermarkOptions.isSemitrasparent(false);

 doc.getWatermark().setText("Aspose Watermark", textWatermarkOptions);

 doc.save(getArtifactsDir() + "Document.TextWatermark.docx");

 // We can remove a watermark from a document like this.
 if (doc.getWatermark().getType() == WatermarkType.TEXT)
     doc.getWatermark().remove();
 

setImage(BufferedImage image)

public void setImage(BufferedImage image)

Adds Image watermark into the document.

Parameters:

ParameterTypeDescription
imagejava.awt.image.BufferedImageImage that is displayed as a watermark.

setImage(BufferedImage image, ImageWatermarkOptions options)

public void setImage(BufferedImage image, ImageWatermarkOptions options)

Adds Image watermark into the document.

Parameters:

ParameterTypeDescription
imagejava.awt.image.BufferedImageImage that is displayed as a watermark.
optionsImageWatermarkOptionsDefines additional options for the image watermark.

setImage(String imagePath, ImageWatermarkOptions options)

public void setImage(String imagePath, ImageWatermarkOptions options)

Adds Image watermark into the document.

Parameters:

ParameterTypeDescription
imagePathjava.lang.StringPath to the image file that is displayed as a watermark.
optionsImageWatermarkOptionsDefines additional options for the image watermark.

setText(String text)

public void setText(String text)

Adds Text watermark into the document.

Parameters:

ParameterTypeDescription
textjava.lang.StringText that is displayed as a watermark.

setText(String text, TextWatermarkOptions options)

public void setText(String text, TextWatermarkOptions options)

Adds Text watermark into the document.

Parameters:

ParameterTypeDescription
textjava.lang.StringText that is displayed as a watermark.
optionsTextWatermarkOptionsDefines additional options for the text watermark.