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.Type before assuming a watermark exists – it returns WatermarkType.None on a document that has never had one set.
  • Setting a new watermark via SetText() or SetImage() replaces any existing watermark; there is no way to have more than one active watermark at a time.
  • Use WatermarkLayout.Diagonal to reproduce Word’s default diagonal watermark orientation, or Horizontal for a watermark that runs parallel to the page edges.
  • Prefer the ImageWatermarkOptions/TextWatermarkOptions overloads over the plain SetImage(image) / SetText(text) calls whenever you need to control opacity, scale, or font – the parameterless overloads use Word’s defaults.

Common Issues

IssueCauseFix
A new watermark doesn’t show alongside the old oneSetText()/SetImage() replaces the existing watermark rather than adding a second oneCall 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 contentImageWatermarkOptions.IsWashout was left disabledSet IsWashout to true when constructing the ImageWatermarkOptions
Text watermark font doesn’t match the intended typefaceTextWatermarkOptions.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 / EnumDescription
WatermarkDocument watermark, via Document.Watermark; SetText(), SetImage(), Remove(), Type
WatermarkTypeEnum identifying the current watermark kind: Text, Image, None
WatermarkLayoutEnum for watermark orientation: Horizontal, Diagonal
TextWatermarkOptionsText watermark formatting: FontFamily, Color, FontSize, IsSemitrasparent, Layout
ImageWatermarkOptionsImage watermark options: Scale, IsWashout

See Also