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 color override for the watermark text.
public string? Color { get; set; }
Property Value
Remarks
When set, this overrides any color defined in the Html template.
Accepts any valid CSS color 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).
Rasterize
Gets or sets whether the watermark is flattened to a raster image baked into every page instead of injected as selectable text/vector content.
public bool Rasterize { get; set; }
Property Value
Remarks
When true, the watermark is rendered to a transparent image and
painted onto each page, so it can't be removed by selecting/deleting text
in a PDF editor (there is no text run and no separate object to delete).
Trade-offs: larger output, no selectable/searchable watermark text, and
slight pixelation at deep zoom. This is tamper-resistance, not
DRM — pixels baked into a page can still be cropped or painted over.
Default false (the watermark stays crisp, selectable vector text).
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 color, overriding any color in the Html template.
public WatermarkOptions WithColor(string cssColor)
Parameters
cssColorstringAny valid CSS color 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));
WithRasterize(bool)
Flattens the watermark to a raster image baked into every page so it can't be removed by selecting/deleting text in a PDF editor.
public WatermarkOptions WithRasterize(bool enable = true)
Parameters
enablebooltrueto rasterize (default);falseto keep the watermark as selectable vector text.
Returns
- WatermarkOptions
The same WatermarkOptions instance for chaining.
Remarks
Tamper-resistance, not DRM: a baked-in image is much harder to remove than selectable text, but a determined user can still crop or paint over it.
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 color, weight, rotation, and opacity.
Returns
- WatermarkOptions
A fully configured WatermarkOptions ready to pass to
WithWatermark.
Examples
engine.WithWatermark(WatermarkOptions.WithText("DRAFT", WatermarkStyle.RedDraft));