---
title: "Add a tiled watermark to PDF pages"
canonical: https://www.graphicsmill.com/samples/Codecs/Pdf/AddWatermark_cs
product: "Graphics Mill"
source: "Codecs/Pdf/AddWatermark.cs"
---

# Add a tiled watermark to PDF pages

This sample shows how to add a semi-transparent, rotated text watermark to every page of an existing PDF file. It demonstrates copying each source page's content into a new PDF with ` PdfReader `, ` PdfWriter `, and ` GraphicsContainer `, then using ` TilingBrush ` to repeat rotated ` PlainText ` across the page as a watermark pattern.

## Instruction

Use the PDF API to add a watermark to every page of an existing PDF: copy each page's original content into a new PDF, then use a rotated TilingBrush to repeat semi-transparent watermark text across the page.

## Usings

```csharp
using System.Linq;
using Aurigma.GraphicsMill.Codecs;
using Aurigma.GraphicsMill.Drawing;
```

## Code Snippet

```csharp
const float dpi = 72;

using (var reader = new PdfReader("GraphicsContainer.pdf", dpi, dpi))
using (var writer = new PdfWriter("GraphicsContainerWithWatermark.pdf"))
using (var graphics = writer.GetGraphics())
{
    foreach (var frame in reader.Frames.OfType<PdfFrame>())
    {
        using (var pageContent = frame.GetContent())
        {
            // Recreate the page with the same size and resolution as the source content.
            writer.AddPage(pageContent.Width, pageContent.Height, pageContent.DpiX, pageContent.DpiY);

            // Copy the original page content before drawing the watermark on top of it.
            graphics.DrawContainer(pageContent, 0, 0);

            var text = new PlainText("watermark text", graphics.CreateFont("Arial", 30))
            {
                Brush = new SolidBrush(RgbColor.Violet.ScaleAlpha(0.25f)),
            };

            // Measure the text so the tile can be sized to fit it exactly.
            var bbox = text.GetBlackBox(graphics.FontRegistry, dpi, dpi);

            var tilingBrush = new TilingBrush(bbox.Width, bbox.Height, dpi, dpi);
            tilingBrush.Graphics.FontRegistry = graphics.FontRegistry;

            // Shift the text so its bounding box starts at the tile's origin, keeping it fully inside the tile.
            tilingBrush.Graphics.Transform.Translate(-bbox.Left, -bbox.Top);
            tilingBrush.Graphics.DrawText(text);

            // Rotate the tile pattern so the repeated watermark text reads diagonally across the page.
            tilingBrush.Transform.Rotate(30);

            // Fill the whole page with the rotated, tiled watermark text.
            graphics.FillRectangle(tilingBrush, 0, 0, graphics.Width, graphics.Height);
        }
    }
}
```

## Explanation

The code:

- Opens the source PDF "GraphicsContainer.pdf" with ` PdfReader ` and creates a new PDF "GraphicsContainerWithWatermark.pdf" with ` PdfWriter `.
- Iterates over the source ` PdfFrame ` pages and, for each one, gets its content as a ` GraphicsContainer ` via ` GetContent `.
- Adds a matching page to the output PDF and draws the original page content onto it with ` Graphics.DrawContainer `.
- Creates watermark ` PlainText ` with a semi-transparent violet brush, and measures its bounding box with ` GetBlackBox `.
- Builds a ` TilingBrush ` sized to the text's bounding box, then draws the text into the brush's own ` Graphics `, translated so it stays fully inside the tile.
- Rotates the tiling brush 30 degrees so the repeated watermark text reads diagonally across the page.
- Fills the whole page with the rotated tiling brush using ` Graphics.FillRectangle `, producing a repeating diagonal watermark.

## Tags

- [Drawing](<https://www.graphicsmill.com/samples/tags/drawing_md>): Drawing vector shapes and text
- [PDF](<https://www.graphicsmill.com/samples/tags/pdf_md>): Importing and exporting PDF documents
- [Text](<https://www.graphicsmill.com/samples/tags/text_md>): Rendering and formatting text
- [Watermark](<https://www.graphicsmill.com/samples/tags/watermark_md>): Adding text or image watermarks

## Input

- [GraphicsContainer.png](<https://www.graphicsmill.com/samples/Codecs/compiled/Debug/GraphicsContainer_png>) (preview)
- [GraphicsContainer.pdf](<https://www.graphicsmill.com/samples/Codecs/compiled/Debug/GraphicsContainer_pdf>) (download)

## Output

- [GraphicsContainerWithWatermark.png](<https://www.graphicsmill.com/samples/Codecs/compiled/Debug/GraphicsContainerWithWatermark_png>) (preview)
- [GraphicsContainerWithWatermark.pdf](<https://www.graphicsmill.com/samples/Codecs/compiled/Debug/GraphicsContainerWithWatermark_pdf>) (download)

## Used APIs

- [Aurigma.GraphicsMill.Codecs.PdfFrame](<https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_Codecs_PdfFrame.htm.md>)
- [Aurigma.GraphicsMill.Codecs.PdfFrame.GetContent](<https://www.graphicsmill.com/docs/gm/M_Aurigma_GraphicsMill_Codecs_PdfFrame_GetContent.htm.md>)
- [Aurigma.GraphicsMill.Codecs.PdfReader](<https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_Codecs_PdfReader.htm.md>)
- [Aurigma.GraphicsMill.Codecs.PdfReader.Frames](<https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_Codecs_PdfReader_Frames.htm.md>)
- [Aurigma.GraphicsMill.Codecs.PdfWriter](<https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_Codecs_PdfWriter.htm.md>)
- [Aurigma.GraphicsMill.Codecs.PdfWriter.AddPage(Single,Single,Single,Single)](<https://www.graphicsmill.com/docs/gm/M_Aurigma_GraphicsMill_Codecs_PdfWriter_AddPage_4_37f6c741.htm.md>)
- [Aurigma.GraphicsMill.Codecs.PdfWriter.GetGraphics](<https://www.graphicsmill.com/docs/gm/M_Aurigma_GraphicsMill_Codecs_PdfWriter_GetGraphics.htm.md>)
- [Aurigma.GraphicsMill.Color.ScaleAlpha(Single)](<https://www.graphicsmill.com/docs/gm/M_Aurigma_GraphicsMill_Color_ScaleAlpha_1_7a94462e.htm.md>)
- [Aurigma.GraphicsMill.Drawing.Graphics.CreateFont(String,Single)](<https://www.graphicsmill.com/docs/gm/M_Aurigma_GraphicsMill_Drawing_Graphics_CreateFont_2_1dbfa9fa.htm.md>)
- [Aurigma.GraphicsMill.Drawing.Graphics.DrawContainer(GraphicsContainer,Single,Single)](<https://www.graphicsmill.com/docs/gm/M_Aurigma_GraphicsMill_Drawing_Graphics_DrawContainer_3_098aa7ce.htm.md>)
- [Aurigma.GraphicsMill.Drawing.Graphics.DrawText(Text)](<https://www.graphicsmill.com/docs/gm/M_Aurigma_GraphicsMill_Drawing_Graphics_DrawText_1_f576d03f.htm.md>)
- [Aurigma.GraphicsMill.Drawing.Graphics.FillRectangle(Brush,Single,Single,Single,Single)](<https://www.graphicsmill.com/docs/gm/M_Aurigma_GraphicsMill_Drawing_Graphics_FillRectangle_5_2d30ad96.htm.md>)
- [Aurigma.GraphicsMill.Drawing.Graphics.FontRegistry](<https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_Drawing_Graphics_FontRegistry.htm.md>)
- [Aurigma.GraphicsMill.Drawing.Graphics.Transform](<https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_Drawing_Graphics_Transform.htm.md>)
- [Aurigma.GraphicsMill.Drawing.GraphicsContainer.DpiX](<https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_Drawing_GraphicsContainer_DpiX.htm.md>)
- [Aurigma.GraphicsMill.Drawing.GraphicsContainer.DpiY](<https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_Drawing_GraphicsContainer_DpiY.htm.md>)
- [Aurigma.GraphicsMill.Drawing.PlainText](<https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_Drawing_PlainText.htm.md>)
- [Aurigma.GraphicsMill.Drawing.SolidBrush](<https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_Drawing_SolidBrush.htm.md>)
- [Aurigma.GraphicsMill.Drawing.Text.Brush](<https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_Drawing_Text_Brush.htm.md>)
- [Aurigma.GraphicsMill.Drawing.Text.GetBlackBox(FontRegistry,Single,Single)](<https://www.graphicsmill.com/docs/gm/M_Aurigma_GraphicsMill_Drawing_Text_GetBlackBox_3_185e8a92.htm.md>)
- [Aurigma.GraphicsMill.Drawing.TilingBrush](<https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_Drawing_TilingBrush.htm.md>)
- [Aurigma.GraphicsMill.Drawing.TilingBrush.Graphics](<https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_Drawing_TilingBrush_Graphics.htm.md>)
- [Aurigma.GraphicsMill.Drawing.TilingBrush.Transform](<https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_Drawing_TilingBrush_Transform.htm.md>)
