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.

Get started with IronPDF

Start using IronPDF in your project today with a free trial.

First Step:
green 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;

// This code demonstrates how to create a PDF document from HTML content
// and stamp text on it using IronPdf library features.

// Create a ChromePdfRenderer which will render HTML into a PDF document.
ChromePdfRenderer renderer = new ChromePdfRenderer();

// Render HTML content as a PDF document.
// The RenderHtmlAsPdf method converts the given HTML string into a PDF.
PdfDocument pdf = renderer.RenderHtmlAsPdf("<h1>Example HTML Document!</h1>");

// Create a TextStamper to add text over the PDF content.
// It allows setting various font properties and alignment.
TextStamper textStamper = new TextStamper
{
    Text = "Text Stamper!", // Text to be stamped on the PDF.
    FontFamily = "Bungee Spice", // Font family for the stamped text.
    UseGoogleFont = true, // Flag indicating whether to use Google Fonts.
    FontSize = 30, // Size of the font.
    IsBold = true, // Make the text bold.
    IsItalic = true, // Make the text italic.
    VerticalAlignment = VerticalAlignment.Top // Position the text at the top.
};

// Apply the text stamp to the PDF.
// The ApplyStamp method adds the defined TextStamper object to the PDF.
pdf.ApplyStamp(textStamper);

// Save the modified PDF to the file system.
// The SaveAs method writes the PDF document to a specified file path.
pdf.SaveAs("stampText.pdf");
Imports IronPdf

Imports IronPdf.Editing



' This code demonstrates how to create a PDF document from HTML content

' and stamp text on it using IronPdf library features.



' Create a ChromePdfRenderer which will render HTML into a PDF document.

Private renderer As New ChromePdfRenderer()



' Render HTML content as a PDF document.

' The RenderHtmlAsPdf method converts the given HTML string into a PDF.

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



' Create a TextStamper to add text over the PDF content.

' It allows setting various font properties and alignment.

Private textStamper As New TextStamper With {

	.Text = "Text Stamper!",

	.FontFamily = "Bungee Spice",

	.UseGoogleFont = True,

	.FontSize = 30,

	.IsBold = True,

	.IsItalic = True,

	.VerticalAlignment = VerticalAlignment.Top

}



' Apply the text stamp to the PDF.

' The ApplyStamp method adds the defined TextStamper object to the PDF.

pdf.ApplyStamp(textStamper)



' Save the modified PDF to the file system.

' The SaveAs method writes the PDF document to a specified file path.

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.

Tips
All 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;

// Initialize a new instance of ChromePdfRenderer to render HTML into PDF
ChromePdfRenderer renderer = new ChromePdfRenderer();

// Render an HTML string into a PDF document
// The HTML content contains a simple heading
PdfDocument pdf = renderer.RenderHtmlAsPdf("<h1>Example HTML Document!</h1>");

// Initialize ImageStamper with the specified URI of the image
// The image URI points to an online SVG image
ImageStamper imageStamper = new ImageStamper(new Uri("https://ironpdf.com/img/svgs/iron-pdf-logo.svg"))
{
    // Set the vertical alignment of the image stamp to be at the top of the page
    VerticalAlignment = VerticalAlignment.Top
};

// Apply the image stamp to the first page of the generated PDF
pdf.ApplyStamp(imageStamper, 0);

// Save the PDF document with the applied stamp to a file named "stampImage.pdf"
pdf.SaveAs("stampImage.pdf");
Imports IronPdf

Imports IronPdf.Editing

Imports System



' Initialize a new instance of ChromePdfRenderer to render HTML into PDF

Private renderer As New ChromePdfRenderer()



' Render an HTML string into a PDF document

' The HTML content contains a simple heading

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



' Initialize ImageStamper with the specified URI of the image

' The image URI points to an online SVG image

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



' Apply the image stamp to the first page of the generated PDF

pdf.ApplyStamp(imageStamper, 0)



' Save the PDF document with the applied stamp to a file named "stampImage.pdf"

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;

// This code demonstrates creating a PDF from HTML content and adding multiple text stamps.

// Initialize a Chrome PDF renderer to convert HTML to PDF
ChromePdfRenderer renderer = new ChromePdfRenderer();

// Render a simple HTML string as a PDF document
PdfDocument pdf = renderer.RenderHtmlAsPdf("<h1>Example HTML Document!</h1>");

// Create the first text stamper with specified text and alignment
TextStamper stamper1 = new TextStamper
{
    Text = "Text stamp 1",
    VerticalAlignment = VerticalAlignment.Top,
    HorizontalAlignment = HorizontalAlignment.Left,
};

// Create the second text stamper with specified text and alignment
TextStamper stamper2 = new TextStamper
{
    Text = "Text stamp 2",
    VerticalAlignment = VerticalAlignment.Top,
    HorizontalAlignment = HorizontalAlignment.Right,
};

// Create an array of stampers to be applied to the PDF
TextStamper[] stampersToApply = { stamper1, stamper2 };

// Apply the array of text stamps to the PDF document
pdf.ApplyStamp(stampersToApply); // Ensure you are using the correct method to apply stamps

// Save the modified PDF document to a file
pdf.SaveAs("multipleStamps.pdf");
Imports IronPdf

Imports IronPdf.Editing



' This code demonstrates creating a PDF from HTML content and adding multiple text stamps.



' Initialize a Chrome PDF renderer to convert HTML to PDF

Private renderer As New ChromePdfRenderer()



' Render a simple HTML string as a PDF document

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



' Create the first text stamper with specified text and alignment

Private stamper1 As New TextStamper With {

	.Text = "Text stamp 1",

	.VerticalAlignment = VerticalAlignment.Top,

	.HorizontalAlignment = HorizontalAlignment.Left

}



' Create the second text stamper with specified text and alignment

Private stamper2 As New TextStamper With {

	.Text = "Text stamp 2",

	.VerticalAlignment = VerticalAlignment.Top,

	.HorizontalAlignment = HorizontalAlignment.Right

}



' Create an array of stampers to be applied to the PDF

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



' Apply the array of text stamps to the PDF document

pdf.ApplyStamp(stampersToApply) ' Ensure you are using the correct method to apply stamps



' Save the modified PDF document to a file

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;

// This code snippet demonstrates creating an image stamper to add an image to a PDF.
// The image is sourced from a URI and positioned on the page with specified offsets.

// Creating an ImageStamper object with the image URL.
ImageStamper imageStamper = new ImageStamper(new Uri("https://ironpdf.com/img/svgs/iron-pdf-logo.svg"))
{
    // Align the image horizontally to the center of the page.
    HorizontalAlignment = HorizontalAlignment.Center,
    
    // Align the image vertically to the top of the page.
    VerticalAlignment = VerticalAlignment.Top,

    // Set horizontal offset (from the centered position).
    HorizontalOffset = new Length(10),

    // Set vertical offset (from the top).
    VerticalOffset = new Length(10),
};

// This ImageStamper object is configured and ready to apply the specified image onto a PDF.
Imports IronPdf.Editing

Imports System



' This code snippet demonstrates creating an image stamper to add an image to a PDF.

' The image is sourced from a URI and positioned on the page with specified offsets.



' Creating an ImageStamper object with the image URL.

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)

}



' This ImageStamper object is configured and ready to apply the specified image onto a PDF.
$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;

/// <summary>
/// Demonstrates rendering an HTML document to a PDF using IronPdf and applying an HTML stamp.
/// </summary>

// Initialize a Chrome PDF renderer, which will be used to convert HTML to PDF
ChromePdfRenderer renderer = new ChromePdfRenderer();

// Define a simple HTML document as a string to be converted to PDF
string htmlDocument = "<h1>Example HTML Document!</h1>";

// Render the HTML document string to a PDF document
PdfDocument pdf = renderer.RenderHtmlAsPdf(htmlDocument);

// Create an HTML stamper for overlaying additional content onto the existing PDF
HtmlStamper htmlStamper = new HtmlStamper
{
    // HTML content for the stamper; this content will be overlaid on the existing PDF
    Html = @"<img src='https://ironpdf.com/img/svgs/iron-pdf-logo.svg'>
    <h1>Iron Software</h1>",

    // Set the alignment for the stamper; in this case, it is aligned to the top
    VerticalAlignment = VerticalAlignment.Top,
};

// Apply the HTML stamper to the PDF document
pdf.ApplyStamp(htmlStamper);

// Save the modified PDF document to a file
pdf.SaveAs("stampHtml.pdf");
Imports IronPdf

Imports IronPdf.Editing



''' <summary>

''' Demonstrates rendering an HTML document to a PDF using IronPdf and applying an HTML stamp.

''' </summary>



' Initialize a Chrome PDF renderer, which will be used to convert HTML to PDF

Private renderer As New ChromePdfRenderer()



' Define a simple HTML document as a string to be converted to PDF

Private htmlDocument As String = "<h1>Example HTML Document!</h1>"



' Render the HTML document string to a PDF document

Private pdf As PdfDocument = renderer.RenderHtmlAsPdf(htmlDocument)



' Create an HTML stamper for overlaying additional content onto the existing PDF

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

}



' Apply the HTML stamper to the PDF document

pdf.ApplyStamp(htmlStamper)



' Save the modified PDF document to a file

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;

// Create an instance of ChromePdfRenderer to render HTML to PDF
ChromePdfRenderer renderer = new ChromePdfRenderer();

// Render HTML content as a PDF document
PdfDocument pdf = renderer.RenderHtmlAsPdf("<h1>Example HTML Document!</h1>");

// Create a barcode stamper with specified text and encoding
// BarcodeEncoding.Code39 is used in this example
BarcodeStamper barcodeStamper = new BarcodeStamper("IronPdf!!", BarcodeEncoding.Code39)
{
    // Set the vertical alignment of the barcode in the PDF
    VerticalAlignment = VerticalAlignment.Top,
};

// Apply the barcode stamp to the rendered PDF document
pdf.ApplyStamp(barcodeStamper);

// Save the stamped PDF document to a file
pdf.SaveAs("stampBarcode.pdf");
Imports IronPdf

Imports IronPdf.Editing



' Create an instance of ChromePdfRenderer to render HTML to PDF

Private renderer As New ChromePdfRenderer()



' Render HTML content as a PDF document

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



' Create a barcode stamper with specified text and encoding

' BarcodeEncoding.Code39 is used in this example

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



' Apply the barcode stamp to the rendered PDF document

pdf.ApplyStamp(barcodeStamper)



' Save the stamped PDF document to a file

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.

Frequently Asked Questions

What is stamping in the context of PDFs?

Stamping in PDFs involves overlaying additional content, such as text or images, onto an existing PDF document. This content, known as a 'stamp,' is often used to add information, labels, watermarks, or annotations.

How do I start stamping text and images in PDFs?

To start stamping text and images in PDFs, you can use IronPDF. Download the C# library via NuGet, create and configure the desired stamper class, and use the ApplyStamp method to apply the stamp to the PDF.

What types of stampers are available for PDF stamping?

IronPDF offers four types of stampers: TextStamper, ImageStamper, HTMLStamper, and BarcodeStamper.

How can I apply a text stamp to a PDF?

Using IronPDF, create an object from the TextStamper class, configure it with properties like text, font family, and location, and pass it to the ApplyStamp method.

Can I apply stamps to specific pages in a PDF document?

Yes, with IronPDF, when using the ApplyStamp method, you can specify the page index to apply the stamp to single or multiple pages.

How can I apply multiple stamps at once to a PDF?

Use the ApplyMultipleStamps method in IronPDF, which allows you to apply multiple stamps by passing an array of stamper objects.

What alignment options are available for stamp placement in PDFs?

In IronPDF, stamp placement can be controlled using a 3x3 grid for horizontal (left, center, right) and vertical (top, middle, bottom) alignment, with additional horizontal and vertical offset options.

How does HTML stamping work in PDFs?

Using IronPDF, the HtmlStamper class allows stamping of HTML content with CSS styling onto a PDF. It supports HTML and CSS features, and you can specify a base URL for HTML assets.

What barcode types are supported for stamping on PDFs?

IronPDF's BarcodeStamper supports QRCode, Code128, and Code39 barcode types.

What additional options are available for customizing stamps in PDFs?

IronPDF provides additional options including Opacity, Rotation, MaxWidth, MaxHeight, Hyperlink, Scale, IsStampBehindContent, WaitFor, and Timeout.

Chaknith related to Explore Stamper Options
Software Engineer
Chaknith is the Sherlock Holmes of developers. It first occurred to him he might have a future in software engineering, when he was doing code challenges for fun. His focus is on IronXL and IronBarcode, but he takes pride in helping customers with every product. Chaknith leverages his knowledge from talking directly with customers, to help further improve the products themselves. His anecdotal feedback goes beyond Jira tickets and supports product development, documentation and marketing, to improve customer’s overall experience.When he isn’t in the office, he can be found learning about machine learning, coding and hiking.