Skip to content

Watermarks

A watermark stamps rotated text - the classic “DRAFT” - behind the content of every page:

doc.Watermark(w => w.Text("DRAFT"));

The defaults match Word’s diagonal watermark: 45° ascending, 15% opacity, medium grey, and a size that auto-fits the page diagonal. Every knob is optional:

doc.Watermark(w => w
.Text("CONFIDENTIAL")
.Color(Colors.Red.Medium) // fill color (its alpha is ignored - Opacity is the knob)
.Opacity(0.3f) // 0 < opacity <= 1, default 0.15
.Rotation(-30f) // counter-clockwise degrees, default 45
.FontSize(48f) // fixed points instead of auto-fit
.FontFamily("Georgia"));

The text must be a single line. Watermark text does not inherit DefaultTextStyle - its appearance comes entirely from these options.

Image stamps a centered image instead, contain-fitted into 70% of the page:

doc.Watermark(w => w
.Image(logoBytes) // same format support as doc.Image - JPEG/PNG as-is, rest converted
.Opacity(0.2f));

Text and image are mutually exclusive. The text-only options (Color, Rotation, FontSize, FontFamily) are only reachable right after Text(...) - chaining them after Image(...) is a compile error, not a runtime one, since image watermarks are never rotated. Opacity is the one option every watermark kind shares.

  • PDF - the watermark is drawn at the start of every page’s content stream, so it sits behind headers, body, and footers. Opacity is true transparency (an ExtGState, PDF/A-conformant); an alpha-PNG’s own transparency multiplies with it.
  • DOCX - the watermark becomes the classic Word idiom: a VML WordArt shape (text) or picture shape (image) in the page header, absolutely centered on the page and behind the text - exactly what Word’s own watermark gallery inserts, and Word lets you edit it afterwards. A header part is created even when the document has no Header(...). Text opacity maps to VML fill opacity; image opacity approximates as Word’s “washout” preset. Sizing uses a per-character approximation rather than measured glyphs, so proportions can differ slightly from the PDF output.
  • XLSX - worksheets have no pages or watermark concept; the watermark is ignored (Excel’s sheet background would not print).
  • HTML - the watermark is an absolutely positioned overlay behind each section’s content. Since flowed HTML has no page boundaries to repeat on, it renders once per section rather than once per printed page. Text and image both work the same as PDF; opacity is CSS opacity, and rotation is a real CSS transform: rotate(...) (negated from the PDF angle so both lean the same way).