Working with Watermarks
Working with Watermarks
This guide shows how to add, configure, and remove document watermarks in
Aspose.Words FOSS for .NET using the Watermark class, reached through
Document.Watermark. A watermark can be text or an image, and only one watermark is active on
a document at a time – setting a new one replaces whatever was there before.
Adding a Text Watermark
Watermark.SetText(text) adds a text watermark with default formatting. The
SetText(text, options) overload takes a TextWatermarkOptions instance to control its
appearance: FontFamily, Color, and FontSize control the text formatting,
IsSemitrasparent toggles the semi-transparent effect typical of watermarks, and Layout (a
WatermarkLayout value – Horizontal or Diagonal) controls its orientation relative to the
page.
Adding an Image Watermark
Watermark.SetImage(image) adds an image watermark from an already-loaded Image. Overloads
that also take an ImageWatermarkOptions instance – SetImage(image, options),
SetImage(imagePath, options) (loading from a file path), and SetImage(imageStream, options)
(loading from a Stream) – let you control Scale (the image’s scale factor, expressed as a
fraction) and IsWashout (the washed-out effect that keeps a watermark image from overpowering
the page content).
Checking and Removing a Watermark
Watermark.Type reports the current watermark’s kind as a WatermarkType value – Text,
Image, or None if no watermark is set. Call Watermark.Remove() to remove the current
watermark from the document.
Tips and Best Practices
- Check
Watermark.Typebefore assuming a watermark exists – it returnsWatermarkType.Noneon a document that has never had one set. - Setting a new watermark via
SetText()orSetImage()replaces any existing watermark; there is no way to have more than one active watermark at a time. - Use
WatermarkLayout.Diagonalto reproduce Word’s default diagonal watermark orientation, orHorizontalfor a watermark that runs parallel to the page edges. - Prefer the
ImageWatermarkOptions/TextWatermarkOptionsoverloads over the plainSetImage(image)/SetText(text)calls whenever you need to control opacity, scale, or font – the parameterless overloads use Word’s defaults.
Common Issues
| Issue | Cause | Fix |
|---|---|---|
| A new watermark doesn’t show alongside the old one | SetText()/SetImage() replaces the existing watermark rather than adding a second one | Call Remove() first only if you need to clear it before setting a different kind; otherwise the replacement is automatic |
| An image watermark overwhelms the page content | ImageWatermarkOptions.IsWashout was left disabled | Set IsWashout to true when constructing the ImageWatermarkOptions |
| Text watermark font doesn’t match the intended typeface | TextWatermarkOptions.FontFamily was not set (or was misspelled) | Set FontFamily to a font name available to the rendering environment |
FAQ
How do I check whether a document already has a watermark?
Read Document.Watermark.Type; it returns WatermarkType.Text, WatermarkType.Image, or
WatermarkType.None.
How do I remove a watermark?
Call Document.Watermark.Remove().
Can I control the watermark’s transparency?
Yes – for text watermarks, set TextWatermarkOptions.IsSemitrasparent; for image watermarks,
set ImageWatermarkOptions.IsWashout.
How do I load an image watermark from disk instead of an in-memory Image?
Use the Watermark.SetImage(imagePath, options) overload, passing the file path as a string
along with an ImageWatermarkOptions instance.
API Reference Summary
| Class / Enum | Description |
|---|---|
Watermark | Document watermark, via Document.Watermark; SetText(), SetImage(), Remove(), Type |
WatermarkType | Enum identifying the current watermark kind: Text, Image, None |
WatermarkLayout | Enum for watermark orientation: Horizontal, Diagonal |
TextWatermarkOptions | Text watermark formatting: FontFamily, Color, FontSize, IsSemitrasparent, Layout |
ImageWatermarkOptions | Image watermark options: Scale, IsWashout |