Class WatermarkOptions
- Namespace
- CobaltPdf
- Assembly
- CobaltPdf.dll
Defines visual settings for a watermark injected into the generated PDF.
public class WatermarkOptions
- Inheritance
-
WatermarkOptions
- Inherited Members
Remarks
The watermark is rendered as HTML and positioned using a full-page overlay before the PDF is generated.
Properties
Color
Gets or sets an optional CSS colour override for the watermark text.
public string? Color { get; set; }
Property Value
Remarks
When set, this overrides any colour defined in the Html template.
Accepts any valid CSS colour value (e.g. "#ff0000", "rgba(0,0,0,0.5)", "red").
Horizontal
Gets or sets the horizontal alignment of the watermark within the page.
public HorizontalAlignment Horizontal { get; set; }
Property Value
Remarks
Controls whether the watermark is positioned at the left, center, or right of the page.
Html
Gets or sets the HTML markup used to render the watermark.
public string Html { get; set; }
Property Value
Remarks
This can include styled text, images, or inline CSS. For quick watermarks without custom HTML, use the WithText(string, WatermarkStyle) factory method instead.
Opacity
Gets or sets the opacity of the watermark.
public double Opacity { get; set; }
Property Value
Remarks
Valid values range from 0.0 (fully transparent)
to 1.0 (fully opaque).
Rotation
Gets or sets the rotation angle, in degrees, applied to the watermark.
public int Rotation { get; set; }
Property Value
Remarks
Positive values rotate clockwise; negative values rotate counterclockwise.
Vertical
Gets or sets the vertical alignment of the watermark within the page.
public VerticalAlignment Vertical { get; set; }
Property Value
Remarks
Controls whether the watermark is positioned at the top, middle, or bottom of the page.
Methods
WithColor(string)
Sets the watermark text colour, overriding any colour in the Html template.
public WatermarkOptions WithColor(string cssColor)
Parameters
cssColorstringAny valid CSS colour value (e.g.
"#ff0000","red","rgba(0,0,0,0.5)").
Returns
- WatermarkOptions
The same WatermarkOptions instance for chaining.
Examples
engine.WithWatermark(
WatermarkOptions.WithText("DRAFT", WatermarkStyle.BoldStamp)
.WithColor("#e74c3c"));
WithHtml(string)
Replaces the generated HTML with a custom HTML/CSS snippet for full control.
public WatermarkOptions WithHtml(string html)
Parameters
htmlstringRaw HTML markup (may include inline CSS, images, etc.).
Returns
- WatermarkOptions
The same WatermarkOptions instance for chaining.
WithOpacity(double)
Sets the opacity of the watermark.
public WatermarkOptions WithOpacity(double opacity)
Parameters
opacitydoubleA value from
0.0(invisible) to1.0(fully opaque).
Returns
- WatermarkOptions
The same WatermarkOptions instance for chaining.
WithPosition(WatermarkPosition)
Sets the watermark position using a single WatermarkPosition value.
public WatermarkOptions WithPosition(WatermarkPosition position)
Parameters
positionWatermarkPositionA combined position that maps to vertical and horizontal alignment.
Returns
- WatermarkOptions
The same WatermarkOptions instance for chaining.
Examples
engine.WithWatermark(
WatermarkOptions.WithText("CONFIDENTIAL", WatermarkStyle.SoftGray)
.WithPosition(WatermarkPosition.TopRight));
WithRotation(int)
Sets the rotation angle of the watermark.
public WatermarkOptions WithRotation(int degrees)
Parameters
degreesintRotation in degrees. Negative values rotate counter-clockwise (e.g.
-45).
Returns
- WatermarkOptions
The same WatermarkOptions instance for chaining.
WithText(string, WatermarkStyle)
Creates a WatermarkOptions with a predefined visual style.
public static WatermarkOptions WithText(string text, WatermarkStyle style = WatermarkStyle.BoldStamp)
Parameters
textstringThe watermark text (e.g. "DRAFT", "CONFIDENTIAL").
styleWatermarkStyleA predefined style that controls colour, weight, rotation, and opacity.
Returns
- WatermarkOptions
A fully configured WatermarkOptions ready to pass to
WithWatermark.
Examples
engine.WithWatermark(WatermarkOptions.WithText("DRAFT", WatermarkStyle.RedDraft));