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.
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();
Methods
Method | Description |
---|---|
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.
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();
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:
Parameter | Type | Description |
---|---|---|
image | java.awt.image.BufferedImage | Image 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:
Parameter | Type | Description |
---|---|---|
image | java.awt.image.BufferedImage | Image that is displayed as a watermark. |
options | ImageWatermarkOptions | Defines 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:
Parameter | Type | Description |
---|---|---|
imagePath | java.lang.String | Path to the image file that is displayed as a watermark. |
options | ImageWatermarkOptions | Defines additional options for the image watermark. |
setText(String text)
public void setText(String text)
Adds Text watermark into the document.
Parameters:
Parameter | Type | Description |
---|---|---|
text | java.lang.String | Text 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:
Parameter | Type | Description |
---|---|---|
text | java.lang.String | Text that is displayed as a watermark. |
options | TextWatermarkOptions | Defines additional options for the text watermark. |