# Add a watermark to a PDF in C#

> Stamp a diagonal, semi transparent DRAFT watermark on every page of a PDF in .NET with the PdfNetStack canvas. MIT licensed, pure C#.

Available since 1.1.

Write a large, rotated, semi transparent word across every page.

## Short answer

Draw on each page with `CreateGraphics`, rotate the canvas about the page center with
`RotateAtTransform`, and draw the text with a color that has an alpha below 1. Positive angles turn
clockwise, so -45 runs the text up from bottom left to top right.

```csharp title="recipe-add-watermark.cs"
#:package PdfNetStack@1.2.0
using PdfNetStack;
using PdfNetStack.Drawing;
using PdfNetStack.Fonts;

PdfDocument doc = PdfDocument.Open("contract.pdf");
PdfFont font = PdfStandardFont.HelveticaBold;
double size = 110;
double width = font.MeasureString("DRAFT", size);
foreach (PdfPage page in doc.Pages)
{
    using PdfGraphics g = page.CreateGraphics();
    g.RotateAtTransform(-45, page.Width / 2, page.Height / 2);   // positive angles turn clockwise
    g.DrawString("DRAFT", font, size, PdfColor.FromHex("#DC2626").WithAlpha(0.25),
        (page.Width - width) / 2, page.Height / 2 + size * 0.35);
}
doc.Save("contract-draft.pdf");
```

![The first page of the contract with a red DRAFT watermark across it](https://www.jadev-corp.com/previews/recipe-watermark.webp)

## Variations

- `page.CreateGraphics(PdfGraphicsLayer.Background)` draws underneath the existing content, so the
  text of the page stays on top of the watermark.
- For an image or a logo, use `DrawImage` or `DrawSvg` the same way. To stamp another PDF page,
  such as a letterhead, use `PdfForm.FromPage` and `DrawForm`, see [Images](https://www.jadev-corp.com/guides/images/).

## Related

- [Drawing](https://www.jadev-corp.com/guides/drawing/)
- [Images](https://www.jadev-corp.com/guides/images/)
- API: [PdfGraphics](https://www.jadev-corp.com/api/pdfnetstack-drawing/pdfgraphics/), [PdfColor](https://www.jadev-corp.com/api/pdfnetstack-drawing/pdfcolor/)

Source: https://www.jadev-corp.com/pdfnetstack/recipes/add-watermark/
