How to Add Stamps & Watermarks to PDFs in C#

In this tutorial, we explore how to stamp text, images, and HTML onto PDFs using Iron PDF in a C# console application. Begin by installing Iron PDF through the NuGet package manager. Set up your environment with an Iron PDF license key, and use the Chrome PDF Renderer to generate a PDF from HTML content.

Create a TextStamper object to customize text properties like font, size, and alignment. For images, use an ImageStamper with specific alignment and offset settings. An HtmlStamper allows embedding HTML content into the PDF. Apply these stampers individually or simultaneously using the ApplyMultipleStamps method, and save the modified PDF using the SaveAs method. This approach streamlines the process, saving time and effort. Finally, the tutorial demonstrates how to run the program and check the output PDF with successfully applied stamps.

For more resources, subscribe to the channel or visit the link in the description to download the software.

using System;
using IronPdf;

class Program
{
    static void Main()
    {
        // Initialize IronPDF with a license key
        var Renderer = new ChromePdfRenderer();

        // Render an initial PDF from HTML
        var pdf = Renderer.RenderHtmlAsPdf("<h1>Hello, IronPDF!</h1>");

        // Stamp text onto the PDF
        var textStamper = new TextStamper("Sample Text")
        {
            FontSize = 16,
            FontFamily = "Arial",
            HorizontalAlignment = IronPdf.Stamper.StampeHorizontalPosition.Center
        };
        textStamper.Stamp(pdf);

        // Stamp an image onto the PDF
        var imageStamper = new ImageStamper(@"path\to\image.png")
        {
            HorizontalAlign = IronPdf.Stamper.StampeHorizontalPosition.Left,
            VerticalAlign = IronPdf.Stamper.StampeVerticalPosition.Top
        };
        imageStamper.Stamp(pdf);

        // Embed HTML content into the PDF
        var htmlStamper = new HtmlStamper("<p>This is an HTML stamp</p>")
        {
            HorizontalAlign = IronPdf.Stamper.StampeHorizontalPosition.Right,
            VerticalAlign = IronPdf.Stamper.StampeVerticalPosition.Bottom
        };
        htmlStamper.Stamp(pdf);

        // Save the modified PDF with applied stamps
        pdf.SaveAs(@"path\to\output.pdf");

        // Confirmation message
        Console.WriteLine("PDF has been stamped and saved successfully.");
    }
}
using System;
using IronPdf;

class Program
{
    static void Main()
    {
        // Initialize IronPDF with a license key
        var Renderer = new ChromePdfRenderer();

        // Render an initial PDF from HTML
        var pdf = Renderer.RenderHtmlAsPdf("<h1>Hello, IronPDF!</h1>");

        // Stamp text onto the PDF
        var textStamper = new TextStamper("Sample Text")
        {
            FontSize = 16,
            FontFamily = "Arial",
            HorizontalAlignment = IronPdf.Stamper.StampeHorizontalPosition.Center
        };
        textStamper.Stamp(pdf);

        // Stamp an image onto the PDF
        var imageStamper = new ImageStamper(@"path\to\image.png")
        {
            HorizontalAlign = IronPdf.Stamper.StampeHorizontalPosition.Left,
            VerticalAlign = IronPdf.Stamper.StampeVerticalPosition.Top
        };
        imageStamper.Stamp(pdf);

        // Embed HTML content into the PDF
        var htmlStamper = new HtmlStamper("<p>This is an HTML stamp</p>")
        {
            HorizontalAlign = IronPdf.Stamper.StampeHorizontalPosition.Right,
            VerticalAlign = IronPdf.Stamper.StampeVerticalPosition.Bottom
        };
        htmlStamper.Stamp(pdf);

        // Save the modified PDF with applied stamps
        pdf.SaveAs(@"path\to\output.pdf");

        // Confirmation message
        Console.WriteLine("PDF has been stamped and saved successfully.");
    }
}
Imports Microsoft.VisualBasic
Imports System
Imports IronPdf

Friend Class Program
	Shared Sub Main()
		' Initialize IronPDF with a license key
		Dim Renderer = New ChromePdfRenderer()

		' Render an initial PDF from HTML
		Dim pdf = Renderer.RenderHtmlAsPdf("<h1>Hello, IronPDF!</h1>")

		' Stamp text onto the PDF
		Dim textStamper As New TextStamper("Sample Text") With {
			.FontSize = 16,
			.FontFamily = "Arial",
			.HorizontalAlignment = IronPdf.Stamper.StampeHorizontalPosition.Center
		}
		textStamper.Stamp(pdf)

		' Stamp an image onto the PDF
		Dim imageStamper As New ImageStamper("path" & vbTab & "o\image.png") With {
			.HorizontalAlign = IronPdf.Stamper.StampeHorizontalPosition.Left,
			.VerticalAlign = IronPdf.Stamper.StampeVerticalPosition.Top
		}
		imageStamper.Stamp(pdf)

		' Embed HTML content into the PDF
		Dim htmlStamper As New HtmlStamper("<p>This is an HTML stamp</p>") With {
			.HorizontalAlign = IronPdf.Stamper.StampeHorizontalPosition.Right,
			.VerticalAlign = IronPdf.Stamper.StampeVerticalPosition.Bottom
		}
		htmlStamper.Stamp(pdf)

		' Save the modified PDF with applied stamps
		pdf.SaveAs("path\to\output.pdf")

		' Confirmation message
		Console.WriteLine("PDF has been stamped and saved successfully.")
	End Sub
End Class
$vbLabelText   $csharpLabel

Further Reading: How to Stamp Text & Image on PDFs

Chipego
Software Engineer
Chipego has a natural skill for listening that helps him to comprehend customer issues, and offer intelligent solutions. He joined the Iron Software team in 2023, after studying a Bachelor of Science in Information Technology. IronPDF and IronOCR are the two products Chipego has been focusing on, but his knowledge of all products is growing daily, as he finds new ways to support customers. He enjoys how collaborative life is at Iron Software, with team members from across the company bringing their varied experience to contribute to effective, innovative solutions. When Chipego is away from his desk, he can often be found enjoying a good book or playing football.
< PREVIOUS
How to Embed UTF-8 Characters in PDF Files Using C#
NEXT >
How to Sign PDF Files in C# Using IronPDF