Cómo agregar sellos y marcas de agua a PDFs en C#

How to Stamp Text & Image on PDFs

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

Stamping text and images on a PDF involves overlaying additional content onto an existing PDF document. This content, often referred to as a "stamp," can be text, images, or a combination of both. Stamps are typically used to add information, labels, watermarks, or annotations to a PDF.

There are a total of 4 stampers that can be used in IronPdf. This article is going to talk about TextStamper, ImageStamper, HTMLStamper, and BarcodeStamper. HTMLStamper is particularly powerful as it can utilize all HTML features along with CSS styling.

Quickstart: Stamp Text on PDFs Instantly

This quick guide demonstrates how to use IronPDF to stamp text onto a PDF file with minimal effort. By leveraging the TextStamper class, developers can easily add text annotations, such as watermarks or labels, to any PDF document. The example below shows a simple implementation of stamping text onto a PDF using the ApplyStamp method, ensuring a fast and efficient stamping process.

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.

    var pdf = new IronPdf.PdfDocument("input.pdf");
    var stamper = new IronPdf.TextStamper("Confidential", 50, 50);
    pdf.ApplyStamp(stamper);
    pdf.SaveAs("stamped.pdf");
  3. Deploy to test on your live environment

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


Stamp Text Example

First, create an object from the TextStamper class. This object will contain all the configurations to specify how we want our text stamper to display. Pass the TextStamper object to the ApplyStamp method. The Text property will be the displayed text. Furthermore, we can specify font family, font styling, as well as the location of the stamp.

:path=/static-assets/pdf/content-code-examples/how-to/stamp-text-image-stamp-text.cs
using IronPdf;
using IronPdf.Editing;

ChromePdfRenderer renderer = new ChromePdfRenderer();

PdfDocument pdf = renderer.RenderHtmlAsPdf("<h1>Example HTML Document!</h1>");

// Create text stamper
TextStamper textStamper = new TextStamper()
{
    Text = "Text Stamper!",
    FontFamily = "Bungee Spice",
    UseGoogleFont = true,
    FontSize = 30,
    IsBold = true,
    IsItalic = true,
    VerticalAlignment = VerticalAlignment.Top,
};

// Stamp the text stamper
pdf.ApplyStamp(textStamper);

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

Private renderer As New ChromePdfRenderer()

Private pdf As PdfDocument = renderer.RenderHtmlAsPdf("<h1>Example HTML Document!</h1>")

' Create text stamper
Private textStamper As New TextStamper() With {
	.Text = "Text Stamper!",
	.FontFamily = "Bungee Spice",
	.UseGoogleFont = True,
	.FontSize = 30,
	.IsBold = True,
	.IsItalic = True,
	.VerticalAlignment = VerticalAlignment.Top
}

' Stamp the text stamper
pdf.ApplyStamp(textStamper)

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

Output PDF

To achieve multi-line text in TextStamper, use the <br> tag as in HTML. For example, "line 1
line 2" will produce "line 1" on the first line and "line 2" on the second line.


Stamp Image Example

Similar to the text stamper, we first create an object from the ImageStamper class and then use the ApplyStamp method to apply the image to the document. The second parameter of this method also accepts a page index, which can be used to apply the stamp to a single or multiple pages. In the example below, we specify that the image should be stamped on page 1 of the PDF.

ConsejosAll page indexes follow zero-based indexing.

:path=/static-assets/pdf/content-code-examples/how-to/stamp-text-image-stamp-image.cs
using IronPdf;
using IronPdf.Editing;
using System;

ChromePdfRenderer renderer = new ChromePdfRenderer();

PdfDocument pdf = renderer.RenderHtmlAsPdf("<h1>Example HTML Document!</h1>");

// Create image stamper
ImageStamper imageStamper = new ImageStamper(new Uri("https://ironpdf.com/img/svgs/iron-pdf-logo.svg"))
{
    VerticalAlignment = VerticalAlignment.Top,
};

// Stamp the image stamper
pdf.ApplyStamp(imageStamper, 0);

pdf.SaveAs("stampImage.pdf");
Imports IronPdf
Imports IronPdf.Editing
Imports System

Private renderer As New ChromePdfRenderer()

Private pdf As PdfDocument = renderer.RenderHtmlAsPdf("<h1>Example HTML Document!</h1>")

' Create image stamper
Private imageStamper As New ImageStamper(New Uri("https://ironpdf.com/img/svgs/iron-pdf-logo.svg")) With {.VerticalAlignment = VerticalAlignment.Top}

' Stamp the image stamper
pdf.ApplyStamp(imageStamper, 0)

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

Output PDF


Apply Multiple Stamps

Use the ApplyMultipleStamps method to apply multiple stamps onto the document by passing an array of stampers to it.

:path=/static-assets/pdf/content-code-examples/how-to/stamp-text-image-multiple-stamps.cs
using IronPdf;
using IronPdf.Editing;

ChromePdfRenderer renderer = new ChromePdfRenderer();

PdfDocument pdf = renderer.RenderHtmlAsPdf("<h1>Example HTML Document!</h1>");

// Create two text stampers
TextStamper stamper1 = new TextStamper()
{
    Text = "Text stamp 1",
    VerticalAlignment = VerticalAlignment.Top,
    HorizontalAlignment = HorizontalAlignment.Left,
};

TextStamper stamper2 = new TextStamper()
{
    Text = "Text stamp 2",
    VerticalAlignment = VerticalAlignment.Top,
    HorizontalAlignment = HorizontalAlignment.Right,
};

Stamper[] stampersToApply = { stamper1, stamper2 };

// Apply multiple stamps
pdf.ApplyMultipleStamps(stampersToApply);

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

Private renderer As New ChromePdfRenderer()

Private pdf As PdfDocument = renderer.RenderHtmlAsPdf("<h1>Example HTML Document!</h1>")

' Create two text stampers
Private stamper1 As New TextStamper() With {
	.Text = "Text stamp 1",
	.VerticalAlignment = VerticalAlignment.Top,
	.HorizontalAlignment = HorizontalAlignment.Left
}

Private stamper2 As New TextStamper() With {
	.Text = "Text stamp 2",
	.VerticalAlignment = VerticalAlignment.Top,
	.HorizontalAlignment = HorizontalAlignment.Right
}

Private stampersToApply() As Stamper = { stamper1, stamper2 }

' Apply multiple stamps
pdf.ApplyMultipleStamps(stampersToApply)

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

Output PDF


Stamp location

To define the placement of the stamp, we utilize a 3x3 grid with three horizontal columns and three vertical rows. You have choices for horizontal alignment: left, center, and right, as well as vertical alignment: top, middle, and bottom. For added precision, you can adjust both horizontal and vertical offsets for each position. Please refer to the image below for a visual representation of this concept.

Stamp location
  • HorizontalAlignment: The horizontal alignment of the stamp relative to the page. The default setting is HorizontalAlignment.Center.
  • VerticalAlignment: The vertical alignment of the stamp relative to the page. The default setting is VerticalAlignment.Middle.
  • HorizontalOffset: The horizontal offset. The default value is 0 and the default unit is IronPdf.Editing.MeasurementUnit.Percentage. Positive values indicate an offset to the right direction, while negative values indicate an offset to the left direction.
  • VerticalOffset: The vertical offset. The default value is 0 and the default unit is IronPdf.Editing.MeasurementUnit.Percentage. Positive values indicate an offset in the downward direction, while negative values indicate an offset in the upward direction.

To specify the HorizontalOffset and VerticalOffset properties, we instantiate the Length class. The default measurement unit for Length is a percentage, but it is also capable of using measurement units such as inches, millimeters, centimeters, pixels, and points.

Code

:path=/static-assets/pdf/content-code-examples/how-to/stamp-text-image-stamp-location.cs
using IronPdf.Editing;
using System;

// Create text stamper
ImageStamper imageStamper = new ImageStamper(new Uri("https://ironpdf.com/img/svgs/iron-pdf-logo.svg"))
{
    HorizontalAlignment = HorizontalAlignment.Center,
    VerticalAlignment = VerticalAlignment.Top,

    // Specify offsets
    HorizontalOffset = new Length(10),
    VerticalOffset = new Length(10),
};
Imports IronPdf.Editing
Imports System

' Create text stamper
Private imageStamper As New ImageStamper(New Uri("https://ironpdf.com/img/svgs/iron-pdf-logo.svg")) With {
	.HorizontalAlignment = HorizontalAlignment.Center,
	.VerticalAlignment = VerticalAlignment.Top,
	.HorizontalOffset = New Length(10),
	.VerticalOffset = New Length(10)
}
$vbLabelText   $csharpLabel

Stamp HTML Example

There is another stamper class that we can use to stamp both text and images. The HtmlStamper class can be used to render HTML designs with CSS styling and then stamp them onto the PDF document. The HtmlBaseUrl property is used to specify the base URL for the HTML string assets, such as CSS and image files.

Code

:path=/static-assets/pdf/content-code-examples/how-to/stamp-text-image-stamp-html.cs
using IronPdf;
using IronPdf.Editing;

ChromePdfRenderer renderer = new ChromePdfRenderer();

PdfDocument pdf = renderer.RenderHtmlAsPdf("<h1>Example HTML Document!</h1>");

// Create HTML stamper
HtmlStamper htmlStamper = new HtmlStamper()
{
    Html = @"<img src='https://ironpdf.com/img/svgs/iron-pdf-logo.svg'>
    <h1>Iron Software</h1>",
    VerticalAlignment = VerticalAlignment.Top,
};

// Stamp the HTML stamper
pdf.ApplyStamp(htmlStamper);

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

Private renderer As New ChromePdfRenderer()

Private pdf As PdfDocument = renderer.RenderHtmlAsPdf("<h1>Example HTML Document!</h1>")

' Create HTML stamper
Private htmlStamper As New HtmlStamper() With {
	.Html = "<img src='https://ironpdf.com/img/svgs/iron-pdf-logo.svg'>
    <h1>Iron Software</h1>",
	.VerticalAlignment = VerticalAlignment.Top
}

' Stamp the HTML stamper
pdf.ApplyStamp(htmlStamper)

pdf.SaveAs("stampHtml.pdf")
$vbLabelText   $csharpLabel
  • Html: The HTML fragment to be stamped onto your PDF. All external references to JavaScript, CSS, and image files will be relative to the HtmlBaseUrl property of the Stamper Class.
  • HtmlBaseUrl: The HTML base URL for which references to external CSS, Javascript, and Image files will be relative.
  • CssMediaType: Enables Media="screen" CSS Styles and StyleSheets. By setting AllowScreenCss=false, IronPdf renders Stamp from HTML using CSS for media="print" as if printing a web page in a browser print dialog. The Default value is PdfCssMediaType.Screen.

Stamp Barcode Example

The BarcodeStamper class can be used to stamp barcode directly on the existing PDF document. The stamper supports barcode types including QRCode, Code128, and Code39.

Code

:path=/static-assets/pdf/content-code-examples/how-to/stamp-text-image-stamp-barcode.cs
using IronPdf;
using IronPdf.Editing;

ChromePdfRenderer renderer = new ChromePdfRenderer();

PdfDocument pdf = renderer.RenderHtmlAsPdf("<h1>Example HTML Document!</h1>");

// Create barcode stamper
BarcodeStamper barcodeStamper = new BarcodeStamper("IronPdf!!", BarcodeEncoding.Code39)
{
    VerticalAlignment = VerticalAlignment.Top,
};

// Stamp the barcode stamper
pdf.ApplyStamp(barcodeStamper);

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

Private renderer As New ChromePdfRenderer()

Private pdf As PdfDocument = renderer.RenderHtmlAsPdf("<h1>Example HTML Document!</h1>")

' Create barcode stamper
Private barcodeStamper As New BarcodeStamper("IronPdf!!", BarcodeEncoding.Code39) With {.VerticalAlignment = VerticalAlignment.Top}

' Stamp the barcode stamper
pdf.ApplyStamp(barcodeStamper)

pdf.SaveAs("stampBarcode.pdf")
$vbLabelText   $csharpLabel
  • Value: The string value of the barcode.
  • BarcodeType: The encoding type for the barcode, with supported types including QRCode, Code128, and Code39. The default is QRCode.
  • Width: The width of the rendered barcode in pixels. The default is 250px.
  • Height: The height of the rendered barcode in pixels. The default is 250px.

Explore Stamper Options

In addition to the options mentioned and explained above, below are more options available to the stamper classes.

  • Opacity: Allows the stamp to be transparent. 0 is fully invisible, 100 is fully opaque.
  • Rotation: Rotates the stamp clockwise from 0 to 360 degrees as specified.
  • MaxWidth: The maximum width of the output stamp.
  • MaxHeight: The maximum height of the output stamp.
  • MinWidth: The minimum width of the output stamp.
  • MinHeight: The minimum height of the output stamp.
  • Hyperlink: Makes stamped elements of this Stamper have an on-click hyperlink. Note: HTML links created by link(a) tags are not reserved by stamping.
  • Scale: Applies a percentage scale to the stamps to make them larger or smaller. Default is 100 (Percent), which has no effect.
  • IsStampBehindContent: Set to true to apply the stamp behind the content. If the content is opaque, the stamp may be invisible.
  • WaitFor: A convenient wrapper to wait for various events or just wait for an amount of time.
  • Timeout: Render timeout in seconds. The default value is 60.

Preguntas Frecuentes

¿Cuál es el propósito de sellar texto e imágenes en PDFs?

Sellar texto e imágenes en PDFs le permite superponer contenido adicional como etiquetas, marcas de agua o anotaciones en documentos PDF existentes. Esto se logra utilizando las diversas clases de estampadores de IronPDF, tales como `TextStamper` e `ImageStamper`.

¿Cómo puedo empezar a sellar texto e imágenes en PDFs usando C#?

Para comenzar a sellar texto e imágenes en PDFs usando C#, instale la biblioteca IronPDF a través de NuGet, configure la clase de estampador apropiada y use el método ApplyStamp para aplicar el sello al PDF.

¿Qué tipos de estampadores puedo usar para sellar PDFs en IronPDF?

IronPDF proporciona varios tipos de estampadores: `TextStamper` para texto, `ImageStamper` para imágenes, `HTMLStamper` para contenido HTML con CSS y `BarcodeStamper` para tipos de códigos de barras como QRCode y otros.

¿Cómo aplico un sello de texto a una página específica en un PDF usando C#?

En IronPDF, puede aplicar un sello de texto a una página específica creando un objeto `TextStamper`, configurando sus propiedades y usando el método ApplyStamp con el parámetro de índice de página para dirigir páginas específicas.

¿Es posible aplicar múltiples sellos simultáneamente en un PDF?

Sí, IronPDF le permite aplicar múltiples sellos a la vez utilizando el método ApplyMultipleStamps, donde puede pasar un arreglo de objetos estampadores configurados.

¿Qué opciones de personalización están disponibles para posicionar sellos en PDFs?

IronPDF permite la personalización del posicionamiento de sellos utilizando una cuadrícula de 3x3 para opciones de alineación, como izquierda, centro, derecha para posiciones horizontales, y superior, medio, inferior para posiciones verticales, junto con configuraciones de desplazamiento adicionales.

¿Se puede utilizar contenido HTML para sellar en PDFs?

Sí, la clase `HTMLStamper` de IronPDF permite que el contenido HTML con estilo CSS se selle en PDFs, ofreciendo una solución versátil para diseños complejos.

¿Qué tipos de códigos de barras admite IronPDF para sellar en PDFs?

El `BarcodeStamper` de IronPDF admite múltiples tipos de códigos de barras, incluidos QRCode, Code128 y Code39, lo que le permite incorporar información de códigos de barras en sus documentos PDF.

¿Qué opciones avanzadas ofrece IronPDF para personalizar sellos en PDFs?

IronPDF proporciona opciones avanzadas de personalización para sellos en PDFs, incluidas propiedades como Opacidad, Rotación, MaxWidth, MaxHeight, Hiperenlace, Escala, IsStampBehindContent, WaitFor y Timeout.

¿Cuáles son los consejos comunes para solucionar problemas de sellado de PDFs con IronPDF?

Asegúrese de tener instalada la versión correcta de IronPDF, verifique las configuraciones de sus objetos estampadores y confirme que su código especifica correctamente los índices de página o áreas donde se aplican los sellos.

¿IronPDF es totalmente compatible con .NET 10 para estampar texto e imágenes en archivos PDF?

Sí, IronPDF es totalmente compatible con .NET 10. Las funciones de estampado como "TextStamper", "ImageStamper", "ApplyStamp", "ApplyMultipleStamps" y las opciones de alineación/personalización funcionan de forma inmediata en proyectos .NET 10 sin necesidad de configuración adicional. Estas funciones son compatibles con todas las plataformas y tipos de proyectos en .NET 10.

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