public class Watermark
extends java.lang.Object
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();
| Modifier and Type | Method and Description |
|---|---|
int |
getType()
Gets the watermark type.
|
void |
remove()
Removes the watermark.
|
void |
setImage(java.awt.image.BufferedImage image)
Adds Image watermark into the document.
|
void |
setImage(java.awt.image.BufferedImage image,
ImageWatermarkOptions options)
Adds Image watermark into the document.
|
void |
setImage(java.io.InputStream imageStream,
ImageWatermarkOptions options)
Adds Image watermark into the document.
|
void |
setImage(java.lang.String imagePath,
ImageWatermarkOptions options)
Adds Image watermark into the document.
|
void |
setText(java.lang.String text)
Adds Text watermark into the document.
|
void |
setText(java.lang.String text,
TextWatermarkOptions options)
Adds Text watermark into the document.
|
public void setText(java.lang.String text)
throws java.lang.Exception
text - Text that is displayed as a watermark.java.lang.IllegalArgumentException - Throws when the text length is out of range or the text contains only whitespaces.com.aspose.words.net.System.ArgumentNullException - Throws when the text is null.
Remarks:
The text length must be in the range from 1 to 200 inclusive. The text cannot be null or contain only whitespaces.
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();
java.lang.Exceptionpublic void setText(java.lang.String text,
TextWatermarkOptions options)
throws java.lang.Exception
text - Text that is displayed as a watermark.options - Defines additional options for the text watermark.java.lang.IllegalArgumentException - Throws when the text length is out of range or the text contain only whitespaces.com.aspose.words.net.System.ArgumentNullException - Throws when the text is null.
Remarks:
The text length must be in the range from 1 to 200 inclusive. The text cannot be null or contain only whitespaces.
If TextWatermarkOptions is null, the watermark will be set with default options.
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();
java.lang.Exceptionpublic void setImage(java.awt.image.BufferedImage image)
throws java.lang.Exception
image - Image that is displayed as a watermark.com.aspose.words.net.System.ArgumentNullException - Throws when the image is null.
Examples:
Shows how to create a watermark from an image in the local file system.
Document doc = new Document();
// Modify the image watermark's appearance with an ImageWatermarkOptions object,
// then pass it while creating a watermark from an image file.
ImageWatermarkOptions imageWatermarkOptions = new ImageWatermarkOptions();
imageWatermarkOptions.setScale(5.0);
imageWatermarkOptions.isWashout(false);
// We have a different options to insert image:
doc.getWatermark().setImage(ImageIO.read(new File(getImageDir() + "Logo.jpg")), imageWatermarkOptions);
doc.getWatermark().setImage(ImageIO.read(new File(getImageDir() + "Logo.jpg")));
doc.getWatermark().setImage(getImageDir() + "Logo.jpg", imageWatermarkOptions);
doc.save(getArtifactsDir() + "Document.ImageWatermark.docx");
java.lang.Exceptionpublic void setImage(java.awt.image.BufferedImage image,
ImageWatermarkOptions options)
throws java.lang.Exception
image - Image that is displayed as a watermark.options - Defines additional options for the image watermark.com.aspose.words.net.System.ArgumentNullException - Throws when the image is null.
Remarks:
If ImageWatermarkOptions is null, the watermark will be set with default options.
Examples:
Shows how to create a watermark from an image in the local file system.
Document doc = new Document();
// Modify the image watermark's appearance with an ImageWatermarkOptions object,
// then pass it while creating a watermark from an image file.
ImageWatermarkOptions imageWatermarkOptions = new ImageWatermarkOptions();
imageWatermarkOptions.setScale(5.0);
imageWatermarkOptions.isWashout(false);
// We have a different options to insert image:
doc.getWatermark().setImage(ImageIO.read(new File(getImageDir() + "Logo.jpg")), imageWatermarkOptions);
doc.getWatermark().setImage(ImageIO.read(new File(getImageDir() + "Logo.jpg")));
doc.getWatermark().setImage(getImageDir() + "Logo.jpg", imageWatermarkOptions);
doc.save(getArtifactsDir() + "Document.ImageWatermark.docx");
java.lang.Exceptionpublic void setImage(java.lang.String imagePath,
ImageWatermarkOptions options)
throws java.lang.Exception
imagePath - Path to the image file that is displayed as a watermark.options - Defines additional options for the image watermark.com.aspose.words.net.System.ArgumentNullException - Throws when the path is null.
Remarks:
If ImageWatermarkOptions is null, the watermark will be set with default options.
Examples:
Shows how to create a watermark from an image in the local file system.
Document doc = new Document();
// Modify the image watermark's appearance with an ImageWatermarkOptions object,
// then pass it while creating a watermark from an image file.
ImageWatermarkOptions imageWatermarkOptions = new ImageWatermarkOptions();
imageWatermarkOptions.setScale(5.0);
imageWatermarkOptions.isWashout(false);
// We have a different options to insert image:
doc.getWatermark().setImage(ImageIO.read(new File(getImageDir() + "Logo.jpg")), imageWatermarkOptions);
doc.getWatermark().setImage(ImageIO.read(new File(getImageDir() + "Logo.jpg")));
doc.getWatermark().setImage(getImageDir() + "Logo.jpg", imageWatermarkOptions);
doc.save(getArtifactsDir() + "Document.ImageWatermark.docx");
java.lang.Exceptionpublic void setImage(java.io.InputStream imageStream,
ImageWatermarkOptions options)
throws java.lang.Exception
imageStream - The stream containing the image data that is displayed as a watermark.options - Defines additional options for the image watermark.com.aspose.words.net.System.ArgumentNullException - Throws when the path is null.
Remarks:
If ImageWatermarkOptions is null, the watermark will be set with default options.
Examples:
Shows how to create a watermark from an image stream.
Document doc = new Document();
// Modify the image watermark's appearance with an ImageWatermarkOptions object,
// then pass it while creating a watermark from an image file.
ImageWatermarkOptions imageWatermarkOptions = new ImageWatermarkOptions();
imageWatermarkOptions.setScale(5.0);
try (FileInputStream imageStream = new FileInputStream(getImageDir() + "Logo.jpg")) {
doc.getWatermark().setImage(imageStream, imageWatermarkOptions);
}
doc.save(getArtifactsDir() + "Document.ImageWatermarkStream.docx");
java.lang.Exceptionpublic int getType()
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();
WatermarkType constants.public void remove()
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();