How to Add Watermarks to PDF Documents Using C#

Published: (December 5, 2025 at 06:51 AM EST)
2 min read
Source: Dev.to

Source: Dev.to

Why Add Watermarks to PDFs

  • Copyright protection – Declare document ownership and deter unauthorized copying.
  • Document status indication – e.g., “DRAFT,” “APPROVED,” or “VOID.”
  • Confidentiality marking – e.g., “CONFIDENTIAL,” “TOP SECRET,” “INTERNAL USE ONLY.”
  • Anti‑forgery tracking – Embed QR codes, serial numbers, or other tracking markers.
  • Branding or personalization – Add company logos or personalized identifiers.

Choosing a PDF Library for C#

LibraryTypeFeaturesLicenseBest Use Case
Spire.PDFCommercialEasy to use, intuitive API, supports conversion, forms, imagesCommercialFast integration with full functionality
iText7Open‑source/CommercialPowerful, enterprise‑grade creation/editing/encryption/signingAGPLv3 / CommercialComplex enterprise‑level customization

Note: iText7’s AGPLv3 license requires your application to be open‑sourced if distributed. For commercial use, a paid license is needed.

Adding a Text Watermark (Spire.PDF)

Install the library via NuGet:

Install-Package Spire.PDF
using Spire.Pdf;
using Spire.Pdf.Graphics;
using System.Drawing;

public class PdfWatermark
{
    public static void AddTextWatermark(string inputFilePath, string outputFilePath, string watermarkText)
    {
        PdfDocument doc = new PdfDocument();
        doc.LoadFromFile(inputFilePath);

        PdfTrueTypeFont font = new PdfTrueTypeFont(new Font("Arial", 24, FontStyle.Bold));
        PdfSolidBrush brush = new PdfSolidBrush(new PdfRGBColor(Color.LightGray));

        foreach (PdfPageBase page in doc.Pages)
        {
            PdfTextWatermark watermark = new PdfTextWatermark(watermarkText)
            {
                Font = font,
                Brush = brush,
                StringFormat = new PdfStringFormat(PdfTextAlignment.Center),
                RotateAngle = -45
            };

            page.AddWatermark(watermark);
        }

        doc.SaveToFile(outputFilePath);
        doc.Close();
    }

    public static void Main(string[] args)
    {
        string inputPdf = "input.pdf";
        string outputPdf = "TextWatermark.pdf";
        string watermarkText = "Confidential";

        AddTextWatermark(inputPdf, outputPdf, watermarkText);
        Console.WriteLine($"Watermark added to {outputPdf}");
    }
}

Steps

  1. Load the PDF with PdfDocument.
  2. Create a font and a semi‑transparent brush.
  3. Iterate through each page and add a PdfTextWatermark (centered, rotated ‑45°).
  4. Save the modified document.

Adding an Image Watermark (Spire.PDF)

using Spire.Pdf;
using System.Drawing;

namespace AddImageWatermark
{
    class Program
    {
        static void Main(string[] args)
        {
            PdfDocument document = new PdfDocument();
            document.LoadFromFile(@"C:\Users\Administrator\Desktop\sample.pdf");

            Image image = Image.FromFile(@"C:\Users\Administrator\Desktop\logo.png");

            int imgWidth = image.Width;
            int imgHeight = image.Height;

            for (int i = 0; i < document.Pages.Count; i++)
            {
                float pageWidth = document.Pages[i].ActualSize.Width;
                float pageHeight = document.Pages[i].ActualSize.Height;

                document.Pages[i].BackgroudOpacity = 0.3f;
                document.Pages[i].BackgroundImage = image;

                Rectangle rect = new Rectangle(
                    (int)(pageWidth - imgWidth) / 2,
                    (int)(pageHeight - imgHeight) / 2,
                    imgWidth,
                    imgHeight);

                document.Pages[i].BackgroundRegion = rect;
            }

            document.SaveToFile("ImageWatermark.pdf");
            document.Close();
        }
    }
}

Steps

  1. Load the source PDF.
  2. Load the watermark image and obtain its dimensions.
  3. For each page, set BackgroudOpacity (e.g., 0.3) and assign BackgroundImage.
  4. Center the image using a Rectangle placed at the middle of the page.
  5. Save the resulting PDF.

Conclusion

Using libraries such as Spire.PDF, you can quickly implement both text and image watermarks in C# applications. These techniques help enforce copyright protection, indicate document status, embed branding, and improve overall document security and traceability.

Back to Blog

Related posts

Read more »

Convert Excel to PDF in C# Applications

Overview Transforming Excel files into polished, share‑ready PDFs doesn’t have to be a slow or complicated process. With the GroupDocs.Conversion Cloud SDK for...