Cómo aplicar marcas de agua personalizadas en PDF en C#

How to Add Watermarks to PDFs in C# Using IronPDF

This article was translated from English: Does it need improvement?
Translated
View the article in English

A custom watermark is a personalized background image or text overlay added to a PDF page. It serves various purposes, including branding with logos or names, enhancing security with labels like 'Confidential,' ensuring copyright protection, and indicating document status. Custom watermarks can include text, images, or both, be applied selectively or universally, and their opacity can be adjusted for versatility in personalizing, securing, and contextualizing PDFs.

IronPDF offers a one-liner to add watermarks to PDF format documents. The watermark feature accepts an HTML string to generate the watermark, which is capable of using all HTML features as well as CSS styling.

Quickstart: Apply Custom Watermarks Effortlessly)

Adding a custom watermark to your PDF has never been easier. With IronPDF, you can apply a watermark using a single line of code. Customize your watermark with HTML styling for opacity, rotation, and location using a simple 3x3 grid system. This guide will help you quickly enhance your PDF documents with personalized watermarks, ensuring both security and branding.

Nuget IconGet started making PDFs with NuGet now:

  1. Install IronPDF with NuGet Package Manager

    PM > Install-Package IronPdf

  2. Copy and run this code snippet.

    new IronPdf.PdfDocument.FromFile("input.pdf")
        .ApplyWatermark("<h1 style='opacity:0.5;'>Confidential</h1>", IronPdf.PagePosition.TopCenter)
        .SaveAs("output.pdf");
  3. Deploy to test on your live environment

    Start using IronPDF in your project today with a free trial
    arrow pointer

as-heading:3(Minimal Workflow (5 Steps)

  1. Download the IronPDF Library for C#
  2. Render a new or import an existing PDF document.
  3. Configure the HTML string to be used as a watermark.
  4. Use the ApplyWatermark method to implement a watermark.
  5. Customize watermark rotation, opacity, and location as needed.

Apply Watermark Example

Utilize the ApplyWatermark method to apply a watermark to a newly rendered PDF or an existing one. This method accepts an HTML string as the watermark, allowing it to have all the features that HTML offers, including CSS styling. Let's use both an image and text as our watermark in the example below. Please note that the watermark will be applied to all the pages; it's not possible to apply the watermark to specific pages.

Code

:path=/static-assets/pdf/content-code-examples/how-to/custom-watermark-apply-watermark.cs
using IronPdf;

string watermarkHtml = @"
<img src='https://ironsoftware.com/img/products/ironpdf-logo-text-dotnet.svg'>
<h1>Iron Software</h1>";

ChromePdfRenderer renderer = new ChromePdfRenderer();

PdfDocument pdf = renderer.RenderHtmlAsPdf("<h1>Watermark</h1>");

// Apply watermark
pdf.ApplyWatermark(watermarkHtml);

pdf.SaveAs("watermark.pdf");
Imports IronPdf

Private watermarkHtml As String = "
<img src='https://ironsoftware.com/img/products/ironpdf-logo-text-dotnet.svg'>
<h1>Iron Software</h1>"

Private renderer As New ChromePdfRenderer()

Private pdf As PdfDocument = renderer.RenderHtmlAsPdf("<h1>Watermark</h1>")

' Apply watermark
pdf.ApplyWatermark(watermarkHtml)

pdf.SaveAs("watermark.pdf")
$vbLabelText   $csharpLabel

Output PDF

This is a very easy way to add image watermark text from a variety of image formats, such as PNG, and text watermark with a custom font.


Watermark Opacity and Rotation

Add a watermark with the default opacity of 50%. This level can be further configured according to the user's requirements. The ApplyWatermark method supports an overload that also accepts rotation as a parameter. By specifying 'rotation:' and 'opacity:', we can adjust these two parameters.

Code

:path=/static-assets/pdf/content-code-examples/how-to/custom-watermark-apply-rotation-opacity.cs
using IronPdf;
using IronPdf.Editing;

string watermarkHtml = @"
<img style='width: 200px;' src='https://ironsoftware.com/img/products/ironpdf-logo-text-dotnet.svg'>
<h1>Iron Software</h1>";

ChromePdfRenderer renderer = new ChromePdfRenderer();

PdfDocument pdf = renderer.RenderHtmlAsPdf("<h1>Watermark</h1>");

// Apply watermark with 45 degrees rotation and 70% opacity
pdf.ApplyWatermark(watermarkHtml, rotation: 45, opacity: 70);

pdf.SaveAs("watermarkOpacity&Rotation.pdf");
Imports IronPdf
Imports IronPdf.Editing

Private watermarkHtml As String = "
<img style='width: 200px;' src='https://ironsoftware.com/img/products/ironpdf-logo-text-dotnet.svg'>
<h1>Iron Software</h1>"

Private renderer As New ChromePdfRenderer()

Private pdf As PdfDocument = renderer.RenderHtmlAsPdf("<h1>Watermark</h1>")

' Apply watermark with 45 degrees rotation and 70% opacity
pdf.ApplyWatermark(watermarkHtml, rotation:= 45, opacity:= 70)

pdf.SaveAs("watermarkOpacity&Rotation.pdf")
$vbLabelText   $csharpLabel

Output PDF


Watermark Location on PDF file

To specify the watermark location, use a 3x3 grid divided into 3 columns horizontally and 3 rows vertically. The horizontal options are left, center, and right, while the vertical options are top, middle, and bottom. With this configuration, we can set 9 different locations on each page of the document. Please refer to the image below for a visual representation of this concept.

Watermark location

Add watermark to a specific location using the VerticalAlignment and HorizontalAlignment enums in the IronPdf.Editing namespace.

Code

:path=/static-assets/pdf/content-code-examples/how-to/custom-watermark-apply-watermark-top-right.cs
using IronPdf;
using IronPdf.Editing;

string watermarkHtml = @"
<img style='width: 200px;' src='https://ironsoftware.com/img/products/ironpdf-logo-text-dotnet.svg'>
<h1>Iron Software</h1>";

ChromePdfRenderer renderer = new ChromePdfRenderer();

PdfDocument pdf = renderer.RenderHtmlAsPdf("<h1>Watermark</h1>");

// Apply watermark on the top-right of the document
pdf.ApplyWatermark(watermarkHtml, 50, VerticalAlignment.Top, HorizontalAlignment.Right);

pdf.SaveAs("watermarkLocation.pdf");
Imports IronPdf
Imports IronPdf.Editing

Private watermarkHtml As String = "
<img style='width: 200px;' src='https://ironsoftware.com/img/products/ironpdf-logo-text-dotnet.svg'>
<h1>Iron Software</h1>"

Private renderer As New ChromePdfRenderer()

Private pdf As PdfDocument = renderer.RenderHtmlAsPdf("<h1>Watermark</h1>")

' Apply watermark on the top-right of the document
pdf.ApplyWatermark(watermarkHtml, 50, VerticalAlignment.Top, HorizontalAlignment.Right)

pdf.SaveAs("watermarkLocation.pdf")
$vbLabelText   $csharpLabel

Output PDF

Ready to see what else you can do? Check out our tutorial page here: Edit PDFs

Preguntas Frecuentes

¿Qué es una marca de agua personalizada en un PDF?

Una marca de agua personalizada es una imagen de fondo o superposición de texto añadida a una página PDF. Sirve para propósitos como branding, seguridad, protección de derechos de autor e indicar el estado del documento.

¿Cómo puedo añadir una marca de agua a un PDF usando C#?

Puedes usar el método ApplyWatermark de IronPDF para añadir una marca de agua a un PDF. Este método acepta una cadena HTML como marca de agua, lo que te permite aprovechar las características de HTML y el estilo CSS.

¿Puedo aplicar una marca de agua solo a ciertas páginas de un PDF?

Actualmente, IronPDF aplica la marca de agua a todas las páginas del PDF. No soporta la aplicación de marcas de agua a páginas específicas.

¿Cómo puedo personalizar la opacidad y rotación de una marca de agua en un PDF?

IronPDF te permite personalizar la opacidad y rotación de una marca de agua usando una sobrecarga del método ApplyWatermark que acepta parámetros para estas propiedades.

¿Qué pasos están involucrados en aplicar marcas de agua personalizadas en C#?

Para aplicar marcas de agua personalizadas, descarga IronPDF, renderiza o importa un PDF, configura una cadena HTML para la marca de agua, usa el método ApplyWatermark y ajusta la rotación, opacidad y ubicación de la marca de agua según sea necesario.

¿Cómo especifico dónde aparece una marca de agua en una página PDF?

Puedes especificar la ubicación de la marca de agua usando un sistema de cuadrícula 3x3 con opciones horizontales (izquierda, centro, derecha) y opciones verticales (arriba, medio, abajo) utilizando los enumerados VerticalAlignment y HorizontalAlignment del espacio de nombres IronPdf.Editing.

¿Qué formatos de imagen puedo usar para las marcas de agua?

IronPDF soporta varios formatos de imagen para crear marcas de agua de imagen, como PNG.

¿Puedo estilizar una marca de agua usando CSS en cadenas HTML?

Sí, IronPDF soporta el estilo CSS en las cadenas HTML usadas para crear marcas de agua, permitiendo una amplia personalización.

¿Es posible combinar texto e imágenes en una sola marca de agua?

Sí, puede combinar texto e imágenes en una sola marca de agua configurando correctamente la cadena HTML utilizada con el método ApplyWatermark .

¿Dónde puedo obtener la biblioteca IronPDF para C#?

Puedes descargar la biblioteca IronPDF para C# desde el gestor de paquetes NuGet.

¿IronPDF es compatible con .NET 10 y las marcas de agua personalizadas funcionarán en proyectos .NET 10?

Sí, IronPDF es totalmente compatible con .NET 10 (además de .NET 9, 8, 7, 6, Core, Standard y Framework).

Chaknith Bin
Ingeniero de Software
Chaknith trabaja en IronXL e IronBarcode. Tiene un profundo conocimiento en C# y .NET, ayudando a mejorar el software y apoyar a los clientes. Sus conocimientos derivados de las interacciones con los usuarios contribuyen a mejores productos, documentación y experiencia en general.
¿Listo para empezar?
Nuget Descargas 16,154,058 | Versión: 2025.11 recién lanzado