# Adding SVG Watermarks to Documents

> This article shows how to add SVG images to document section headers that repeat automatically on each page. This watermark will be inserted vertically and horizontally centered on each section page.

- **Author:** Bjoern Meyer
- **Published:** 2022-01-28
- **Modified:** 2026-07-17
- **Description:** This article shows how to add SVG images to document section headers that repeat automatically on each page. This watermark will be inserted vertically and horizontally centered on each section page.
- **3 min read** (575 words)
- **Tags:**
  - ASP.NET
  - ASP.NET Core
  - MailMerge
  - Tutorial
- **Web URL:** https://www.textcontrol.com/blog/2022/01/28/adding-svg-watermarks-to-documents/
- **LLMs URL:** https://www.textcontrol.com/blog/2022/01/28/adding-svg-watermarks-to-documents/llms.txt
- **LLMs-Full URL:** https://www.textcontrol.com/blog/2022/01/28/adding-svg-watermarks-to-documents/llms-full.txt

---

In order to add watermarks to documents, images are inserted into a page headers of each section. The content of headers (and footers) are repeated on each page automatically. FrameBase objects including images can be inserted into a header by overlapping the main text.

### Scalable SVG Images

Since version 30.0, TX Text Control [supports the insertion of SVG images](https://www.textcontrol.com/blog/2021/07/13/text-control-30-preview-inserting-svg-images/llms-full.txt) which is the preferred image format for watermarks. The advantage of using SVG images is that they, as the name "Scalable Vector Graphics" implies, are scalable. One SVG image can be used for all required sizes in any document.

![Watermark in TX Text Control](https://s1-www.textcontrol.com/assets/dist/blog/2022/01/28/a/assets/background.webp "Watermark in TX Text Control")

### Positioned Behind Text

Additionally, objects can be positioned behind the actual text, so that the text is still visible and the watermark can be seen virtually in the background of a document. To achieve this, the following implementation of the Images.Add method must be used:

```
public bool Add(Image image,
                int pageNumber, 
                System.Drawing.Point location,
                ImageInsertionMode insertionMode);
```

The required enumeration combination for the *InsertionMode* is *FixedOnPage* and *BelowTheText*:

```
hf.Images.Add(image,
	      1,
	      new System.Drawing.Point(0, 0),
	      TXTextControl.ImageInsertionMode.FixedOnPage |
	      TXTextControl.ImageInsertionMode.BelowTheText);
```

### Center the Image

Finally, the image must be centered vertically and horizontally on each page of each section in case there are different page sizes and orientations. The following formula is used to calculate the location of the background images:

**(\[Page width\] - \[image width\] - \[both page margins\]) / 2**

The following diagram shows the various values that must be considered into the calculation of the exact horizontal location:

![Center image](https://s1-www.textcontrol.com/assets/dist/blog/2022/01/28/a/assets/image-calculation.webp "Center image")

The following method *AddWatermark* creates headers for each section in order to insert a watermark centered on each page of the document:

```
public void AddWatermark(TXTextControl.ServerTextControl tx, string imagePath)
{
    foreach (TXTextControl.Section section in tx.Sections)
    {
        // remove existing headers for demo purposes
        section.HeadersAndFooters.Remove(TXTextControl.HeaderFooterType.All);

        // add new header for each section
        section.HeadersAndFooters.Add(TXTextControl.HeaderFooterType.Header);
        TXTextControl.HeaderFooter hf = 
            (section.HeadersAndFooters.GetItem(TXTextControl.HeaderFooterType.Header));

        // add the watermark
        TXTextControl.Image image = new TXTextControl.Image();
        image.FileName = imagePath;

        hf.Images.Add(
            image,
            1,
            new System.Drawing.Point(0, 0),
            TXTextControl.ImageInsertionMode.FixedOnPage |
            TXTextControl.ImageInsertionMode.BelowTheText);

        // calculate the horizontal center location
        var pageWidth = (int)section.Format.PageSize.Width;
        var pageMarginsHorizontal = (int)(section.Format.PageMargins.Left +
            section.Format.PageMargins.Right);
        var imageWidth = image.Size.Width;
        int locationX = (pageWidth - imageWidth - pageMarginsHorizontal) / 2;

        // calculate the vertical center location
        var pageHeight = (int)section.Format.PageSize.Height;
        var pageMarginsVertical = (int)(section.Format.PageMargins.Top +
            section.Format.PageMargins.Bottom);
        var imageHeight = image.Size.Height;

        int locationY = (pageHeight - imageHeight - pageMarginsVertical) / 2;

        // set the location
        image.Location = new System.Drawing.Point(locationX, locationY);
    }
}
```

This method is called with an instance of a *ServerTextControl* (same code is compatible to Windows Forms and WPF) and a path to the image. In the following code, an *HttpGet* method is implemented to load any document to add a watermark to the document pages:

```
[HttpGet]
public IActionResult AddWatermark()
{

    byte[] bDocument;

    // create a ServerTextControl
    using (TXTextControl.ServerTextControl tx = new TXTextControl.ServerTextControl()) { 

        tx.Create();
        tx.PageUnit = TXTextControl.MeasuringUnit.Twips;

         // load the template
        tx.Load("App_Data/nda.tx", TXTextControl.StreamType.InternalUnicodeFormat);

        AddWatermark(tx, "App_Data/draft.svg");

        // save in the internal format
        tx.Save(out bDocument, TXTextControl.BinaryStreamType.InternalUnicodeFormat);
    }

    return Ok(bDocument);
}
```

---

## About Bjoern Meyer

As CEO, Bjoern is the visionary behind our strategic direction and business development, bridging the gap between our customers and engineering teams. His deep passion for coding and web technologies drives the creation of innovative products. If you're at a tech conference, be sure to stop by our booth - you'll most likely meet Bjoern in person. With an advanced graduate degree (Dipl. Inf.) in Computer Science, specializing in AI, from the University of Bremen, Bjoern brings significant expertise to his role. In his spare time, Bjoern enjoys running, paragliding, mountain biking, and playing the piano.

- [LinkedIn](https://www.linkedin.com/in/bjoernmeyer/)
- [X](https://x.com/txbjoern)
- [GitHub](https://github.com/bjoerntx)

---

## Related Posts

- [How to Mail Merge MS Word DOCX Documents in ASP.NET Core C#](https://www.textcontrol.com/blog/2023/10/16/how-to-mail-merge-ms-word-docx-documents-in-aspnet-core-csharp/llms.txt)
- [Using MailMerge in ASP.NET Core 6 Web Applications](https://www.textcontrol.com/blog/2022/01/27/using-mailmerge-in-aspnet-core-6-web-applications/llms.txt)
- [Create SignFabric Envelopes from Mail Merge Templates in .NET C#](https://www.textcontrol.com/blog/2026/06/23/create-signfabric-envelopes-from-mail-merge-templates-using-dotnet-csharp/llms.txt)
- [Use MailMerge in .NET on Linux to Generate Pixel-Perfect PDFs from DOCX Templates](https://www.textcontrol.com/blog/2025/05/27/use-mailmerge-in-dotnet-on-linux-to-generate-pixel-perfect-pdfs-from-docx-templates/llms.txt)
- [Generating Dynamic NDAs Using TX Text Control MailMerge in C# .NET](https://www.textcontrol.com/blog/2025/04/08/generating-dynamic-ndas-using-tx-text-control-mailmerge-in-csharp-dotnet/llms.txt)
- [Designing a Maintainable PDF Generation Web API in ASP.NET Core (Linux) C# with Clean Architecture and TX Text Control](https://www.textcontrol.com/blog/2025/03/27/designing-a-maintainable-pdf-generation-web-api-in-asp-net-core-linux-c-sharp-with-clean-architecture-and-tx-text-control/llms.txt)
- [Manipulating Table Cells During the MailMerge Process in .NET C#](https://www.textcontrol.com/blog/2024/12/03/manipulating-table-cells-during-the-mailmerge-process-in-net-csharp/llms.txt)
- [When to Generate Documents Server-Side Instead of Client-Side: A Focus on Data Security](https://www.textcontrol.com/blog/2024/10/04/when-to-generate-documents-server-side-instead-of-client-side-a-focus-on-data-security/llms.txt)
- [Mail Merge: Inserting Merge Blocks using the DataSourceManager in C#](https://www.textcontrol.com/blog/2024/10/02/mail-merge-inserting-merge-blocks-using-the-datasourcemanager-in-csharp/llms.txt)
- [Creating Advanced Tables in PDF and DOCX Documents with C#](https://www.textcontrol.com/blog/2024/09/30/creating-advanced-tables-in-pdf-and-docx-documents-with-csharp/llms.txt)
- [Designing the Perfect Contract Template for MailMerge in C#](https://www.textcontrol.com/blog/2024/09/26/designing-the-perfect-contract-template-for-mailmerge-in-csharp/llms.txt)
- [Video Tutorial: Creating a MailMerge Template and JSON Data Structure](https://www.textcontrol.com/blog/2024/08/16/video-tutorial-creating-a-mailmerge-template-and-json-data-structure/llms.txt)
- [Getting Started Video Tutorial: How to use the MailMerge and ServerTextControl Classes in ASP.NET Core C#](https://www.textcontrol.com/blog/2024/08/05/getting-started-video-tutorial-how-to-use-the-mailmerge-and-servertextcontrol-classes-in-asp-net-core-c/llms.txt)
- [Getting Started Videos: New Text Control YouTube Channel](https://www.textcontrol.com/blog/2024/08/02/getting-started-videos-new-text-control-youtube-channel/llms.txt)
- [Best Practices for Mail Merge and Form Field Processing in ASP.NET Core C# Applications](https://www.textcontrol.com/blog/2024/07/30/best-practices-for-mail-merge-and-form-field-processing-in-asp-net-core-csharp-applications/llms.txt)
- [Advantages of Flow Type Layout Reporting vs. Banded Reporting or PDF Template Engines in .NET C#](https://www.textcontrol.com/blog/2024/07/29/advantages-of-flow-type-layout-reporting-vs-banded-reporting-or-pdf-template-engines-in-net-c-sharp/llms.txt)
- [Designing a MailMerge Web API Endpoint with ASP.NET Core in C#](https://www.textcontrol.com/blog/2024/07/12/designing-a-mailmerge-web-api-endpoint-with-asp-net-core-in-c-sharp/llms.txt)
- [Enhancing Documents with QR Codes and Barcodes in .NET C#: A Comprehensive Guide](https://www.textcontrol.com/blog/2024/07/11/enhancing-documents-with-qr-codes-and-barcodes-in-net-csharp-a-comprehensive-guide/llms.txt)
- [Document Automation 101: Leveraging TX Text Control for Business Efficiency in .NET C# Applications](https://www.textcontrol.com/blog/2024/07/09/document-automation-101-leveraging-tx-text-control-for-business-efficiency-in-net-c-applications/llms.txt)
- [Merging Templates with MailMerge with Different Merge Field Settings in C#](https://www.textcontrol.com/blog/2023/12/16/merging-templates-with-mailmerge-with-different-merge-field-settings/llms.txt)
- [MailMerge: Working with Image Placeholders](https://www.textcontrol.com/blog/2022/12/22/mailmerge-working-with-image-placeholders/llms.txt)
- [Getting Started: ServerTextControl and MailMerge with ASP.NET Core](https://www.textcontrol.com/blog/2022/09/01/getting-started-servertextcontrol-and-mailmerge-with-aspnet-core/llms.txt)
- [AI Natural Language Document Generation with MCP and TX Text Control .NET](https://www.textcontrol.com/blog/2026/07/16/ai-natural-language-document-generation-with-mcp-server-and-tx-text-control-dotnet/llms.txt)
- [WeAreDevelopers World Congress Europe 2026 Wrap Up: Record Breaking Days in Berlin](https://www.textcontrol.com/blog/2026/07/13/wearedevelopers-world-congress-europe-2026-wrap-up-record-breaking-days-in-berlin/llms.txt)
- [C# Document Generation: A Developer's Guide for .NET](https://www.textcontrol.com/blog/2026/07/08/csharp-document-generation-developer-guide-for-dotnet/llms.txt)
