Stamping & Watermarks
Apply text stamps, image stamps, and watermarks to every page of a PDF. FolioPDF generates each stamp as a transparent overlay using its layout engine, then composites it via the native qpdf pipeline — so stamps support the full typography and image codec capabilities of the library.
Text Stamps
Use StampText to place a text label on every page. The stamp is positioned according to its alignment and margin settings:
PdfEditor.Open("report.pdf")
.StampText(new TextStamp("CONFIDENTIAL")
{
FontSize = 48,
Color = Color.FromHex("#CC0000"),
Opacity = 0.3f,
Rotation = -45,
HorizontalAlignment = StampAlignment.Center,
VerticalAlignment = StampAlignment.Center
})
.Save("report-stamped.pdf");
TextStamp Properties
| Property | Type | Default | Description |
|---|---|---|---|
Text | string | — | The text to stamp. Set via constructor. Required. |
FontSize | float | 36 | Font size in points. |
Color | Color? | Black | Text colour. Use Color.FromHex, Color.FromRgb, or named colours. |
Opacity | float | 0.5 | Transparency from 0 (invisible) to 1 (fully opaque). |
Rotation | float | 0 | Rotation angle in degrees. Negative values rotate counter-clockwise. |
Bold | bool | false | Render text in bold weight. |
Italic | bool | false | Render text in italic style. |
HorizontalAlignment | StampAlignment | Center | Horizontal position on the page. |
VerticalAlignment | StampAlignment | Center | Vertical position on the page. |
Margin | float | 20 | Distance from the page edge in points. |
BehindContent | bool | false | When true, the stamp is placed behind existing page content (underlay). When false, it is drawn on top (overlay). |
StampAlignment Enum
| Value | Horizontal Meaning | Vertical Meaning |
|---|---|---|
Start | Left edge | Top edge |
Center | Horizontally centred | Vertically centred |
End | Right edge | Bottom edge |
Image Stamps
Use StampImage to place a logo, badge, or other image on every page:
PdfEditor.Open("report.pdf")
.StampImage(new ImageStamp("company-logo.png")
{
Width = 120,
Height = 40,
HorizontalAlignment = StampAlignment.End,
VerticalAlignment = StampAlignment.Start,
Margin = 30
})
.Save("report-branded.pdf");
Creating from Bytes
When the image is already in memory (e.g. from a database or API), pass the byte array directly:
byte[] logo = await httpClient.GetByteArrayAsync(logoUrl);
PdfEditor.Open("proposal.pdf")
.StampImage(new ImageStamp(logo)
{
Width = 100,
Height = 100,
HorizontalAlignment = StampAlignment.Center,
VerticalAlignment = StampAlignment.Center
})
.Save("proposal-stamped.pdf");
ImageStamp Properties
| Property | Type | Default | Description |
|---|---|---|---|
ImageBytes | byte[] | — | Image data (PNG, JPEG, WebP, BMP, GIF). Set via constructor. |
Width | float | 0 | Desired width in points. 0 = automatic from aspect ratio. |
Height | float | 0 | Desired height in points. 0 = automatic from aspect ratio. |
Rotation | float | 0 | Rotation angle in degrees. |
HorizontalAlignment | StampAlignment | End | Horizontal position on the page. |
VerticalAlignment | StampAlignment | Start | Vertical position on the page. |
Margin | float | 20 | Distance from the page edge in points. |
BehindContent | bool | false | When true, the image is placed behind existing content. |
Supported formats. Image stamps accept any format FolioPDF's native Skia engine can decode: PNG, JPEG, WebP, BMP, and GIF. SVG is not supported for stamps — rasterise SVGs first using the layout engine.
Watermark Patterns
Diagonal "DRAFT" Watermark
The classic diagonal watermark uses large, semi-transparent text rotated at -45 degrees:
PdfEditor.Open("proposal.pdf")
.StampText(new TextStamp("DRAFT")
{
FontSize = 72,
Color = Color.FromRgb(200, 200, 200),
Opacity = 0.25f,
Rotation = -45,
Bold = true,
HorizontalAlignment = StampAlignment.Center,
VerticalAlignment = StampAlignment.Center
})
.Save("proposal-draft.pdf");
Diagonal "CONFIDENTIAL" Watermark in Red
PdfEditor.Open("financials.pdf")
.StampText(new TextStamp("CONFIDENTIAL")
{
FontSize = 60,
Color = Color.FromHex("#FF0000"),
Opacity = 0.15f,
Rotation = -45,
Bold = true,
HorizontalAlignment = StampAlignment.Center,
VerticalAlignment = StampAlignment.Center
})
.Save("financials-confidential.pdf");
Corner Logo Branding
Place a company logo in the top-right corner of every page:
PdfEditor.Open("whitepaper.pdf")
.StampImage(new ImageStamp("brand-logo.png")
{
Width = 80,
Height = 30,
HorizontalAlignment = StampAlignment.End,
VerticalAlignment = StampAlignment.Start,
Margin = 25
})
.Save("whitepaper-branded.pdf");
Bottom-Left Date Stamp
var dateText = $"Printed: {DateTime.Now:yyyy-MM-dd HH:mm}";
PdfEditor.Open("report.pdf")
.StampText(new TextStamp(dateText)
{
FontSize = 9,
Color = Color.FromRgb(128, 128, 128),
Opacity = 1.0f,
HorizontalAlignment = StampAlignment.Start,
VerticalAlignment = StampAlignment.End,
Margin = 30
})
.Save("report-dated.pdf");
Centred "VOID" Stamp
PdfEditor.Open("cancelled-invoice.pdf")
.StampText(new TextStamp("VOID")
{
FontSize = 96,
Color = Color.FromHex("#CC0000"),
Opacity = 0.4f,
Bold = true,
HorizontalAlignment = StampAlignment.Center,
VerticalAlignment = StampAlignment.Center
})
.Save("invoice-voided.pdf");
Background Watermark (Behind Content)
Set BehindContent = true to place the stamp underneath existing page content. This is useful for light background patterns that should not obscure text:
PdfEditor.Open("form.pdf")
.StampText(new TextStamp("SAMPLE")
{
FontSize = 100,
Color = Color.FromRgb(230, 230, 230),
Opacity = 0.5f,
Rotation = -45,
Bold = true,
BehindContent = true,
HorizontalAlignment = StampAlignment.Center,
VerticalAlignment = StampAlignment.Center
})
.Save("form-sample.pdf");
Combining Stamps
Chain multiple stamps in a single editor session. Each stamp is applied sequentially:
PdfEditor.Open("contract.pdf")
// Logo in top-right corner
.StampImage(new ImageStamp("logo.png")
{
Width = 100,
Height = 35,
HorizontalAlignment = StampAlignment.End,
VerticalAlignment = StampAlignment.Start,
Margin = 25
})
// Date in bottom-left
.StampText(new TextStamp($"Generated: {DateTime.Now:yyyy-MM-dd}")
{
FontSize = 8,
Color = Color.FromRgb(100, 100, 100),
Opacity = 1.0f,
HorizontalAlignment = StampAlignment.Start,
VerticalAlignment = StampAlignment.End,
Margin = 25
})
// Diagonal watermark
.StampText(new TextStamp("DRAFT")
{
FontSize = 72,
Opacity = 0.15f,
Rotation = -45,
Bold = true,
Color = Color.FromRgb(200, 200, 200)
})
.Save("contract-marked.pdf");
Static API
For one-off stamping without a full editor chain, use the static PdfStamper methods directly:
// File-to-file
PdfStamper.StampText("input.pdf", "output.pdf", new TextStamp("APPROVED")
{
FontSize = 36,
Color = Color.FromHex("#008000"),
Opacity = 0.5f,
HorizontalAlignment = StampAlignment.End,
VerticalAlignment = StampAlignment.End,
Margin = 40
});
// In-memory
byte[] pdfBytes = File.ReadAllBytes("input.pdf");
byte[] stamped = PdfStamper.StampText(pdfBytes, new TextStamp("COPY"));
File.WriteAllBytes("output.pdf", stamped);
// Image stamp, file-to-file
PdfStamper.StampImage("input.pdf", "output.pdf",
new ImageStamp("logo.png") { Width = 80, Height = 30 });
How Stamping Works Internally
Understanding the internals helps when troubleshooting sizing or alignment issues:
- FolioPDF reads the first page's dimensions from the target PDF.
- A transparent single-page PDF is generated using the layout engine with the same page size, containing just the stamp content at the requested position.
- The overlay (or underlay, if
BehindContent = true) is applied to every page of the target document via qpdf's overlay/underlay pipeline. - The result is a new PDF with the stamp composited onto every page.
Page size matching. The stamp overlay is generated at the dimensions of the first page of the target PDF. If your document has pages of varying sizes, the stamp will be positioned relative to the first page's dimensions on every page.
Next Steps
- Drawing on Pages — draw text, lines, and rectangles directly onto page content
- Merge, Split & Overlay — qpdf-level overlay and underlay with full page mapping
- Page Manipulation — rotation, cropping, and page boxes