Stamp HTML onto Existing PDF C#

Whether you need to stamp, authorize, or add a watermark to a PDF, it is important you get the process right to convey correct usage restrictions. To stamp a PDF document correctly and efficiently in C#, we will use the IronPDF functions following the steps below.


Step 1

1. Install IronPDF Library to your .NET Project

Step one is to install the IronPDF Library to your .NET Project. Some may find it convenient to download directly while others may wish to navigate to NuGet in order to access the Library. Either method is applicable for this use. Additionally you can use the software free of charge for unlimited days within a development environment.


 PM > Install-Package IronPdf

How to Tutorial

2. Stamp a C# PDF

Stamping / Watermark

Stamping or Authorizing a PDF is really important for many document settings and use cases in .NET applications.

Now that we have IronPDF installed, it will be a simple function to apply stamp to your document.

In the below example, we have selected a PDF file. Using the "HtmlStamper()" function, on a note to use 'IsStampBehindContent = true', the data which we select will get displayed on the BACK of a PDF.

Alternatively, with 'IsStampBehindContent = false' , we will display the stamp ABOVE the PDF file.

Here is an example of how these functions could be incorporated into your project.

using IronPdf;
using IronPdf.Editing;

namespace StampHtml
{
    class Program
    {
        static void Main()
        {
            // Load PDF to be Stamped/Watermarked with new HTML content into the foreground or background.
            PdfDocument pdf = PdfDocument.FromFile("sample.pdf");

            // Below are the two examples for Behind or Above Html Stamp of PDF

            // Set Logo as a Watermark with HtmlStamper
            var backgroundStamp = new HtmlStamper("<img src='https://ironpdf.com/img/products/ironpdf-logo-text-dotnet.svg'/>")
            {
                Opacity = 50,
                VerticalAlignment = VerticalAlignment.Top,
                HorizontalAlignment = HorizontalAlignment.Right,
                IsStampBehindContent = true,
            };
            pdf.ApplyStamp(backgroundStamp);

            // Set Text as a Verified with HtmlStamper
            var foregroundStamp = new HtmlStamper("<h2 style='color:red'>Copyright 2022 IronPDF.com</h2>")
            {
                MaxWidth = new Length(50),
                MaxHeight = new Length(50),
                Opacity = 50,
                Rotation = -45,
                IsStampBehindContent = false,
            };
            pdf.ApplyStamp(foregroundStamp);

            // Save the PDF with stamps to desire location
            pdf.SaveAs("Stamped.pdf");
        }
    }
}
using IronPdf;
using IronPdf.Editing;

namespace StampHtml
{
    class Program
    {
        static void Main()
        {
            // Load PDF to be Stamped/Watermarked with new HTML content into the foreground or background.
            PdfDocument pdf = PdfDocument.FromFile("sample.pdf");

            // Below are the two examples for Behind or Above Html Stamp of PDF

            // Set Logo as a Watermark with HtmlStamper
            var backgroundStamp = new HtmlStamper("<img src='https://ironpdf.com/img/products/ironpdf-logo-text-dotnet.svg'/>")
            {
                Opacity = 50,
                VerticalAlignment = VerticalAlignment.Top,
                HorizontalAlignment = HorizontalAlignment.Right,
                IsStampBehindContent = true,
            };
            pdf.ApplyStamp(backgroundStamp);

            // Set Text as a Verified with HtmlStamper
            var foregroundStamp = new HtmlStamper("<h2 style='color:red'>Copyright 2022 IronPDF.com</h2>")
            {
                MaxWidth = new Length(50),
                MaxHeight = new Length(50),
                Opacity = 50,
                Rotation = -45,
                IsStampBehindContent = false,
            };
            pdf.ApplyStamp(foregroundStamp);

            // Save the PDF with stamps to desire location
            pdf.SaveAs("Stamped.pdf");
        }
    }
}
Imports IronPdf
Imports IronPdf.Editing

Namespace StampHtml
	Friend Class Program
		Shared Sub Main()
			' Load PDF to be Stamped/Watermarked with new HTML content into the foreground or background.
			Dim pdf As PdfDocument = PdfDocument.FromFile("sample.pdf")

			' Below are the two examples for Behind or Above Html Stamp of PDF

			' Set Logo as a Watermark with HtmlStamper
			Dim backgroundStamp = New HtmlStamper("<img src='https://ironpdf.com/img/products/ironpdf-logo-text-dotnet.svg'/>") With {
				.Opacity = 50,
				.VerticalAlignment = VerticalAlignment.Top,
				.HorizontalAlignment = HorizontalAlignment.Right,
				.IsStampBehindContent = True
			}
			pdf.ApplyStamp(backgroundStamp)

			' Set Text as a Verified with HtmlStamper
			Dim foregroundStamp = New HtmlStamper("<h2 style='color:red'>Copyright 2022 IronPDF.com</h2>") With {
				.MaxWidth = New Length(50),
				.MaxHeight = New Length(50),
				.Opacity = 50,
				.Rotation = -45,
				.IsStampBehindContent = False
			}
			pdf.ApplyStamp(foregroundStamp)

			' Save the PDF with stamps to desire location
			pdf.SaveAs("Stamped.pdf")
		End Sub
	End Class
End Namespace
VB   C#

3. Reliable Stamped Documents

Stamping a PDF will create more reliability & authenticity for a document. IronPDF makes it really simple for a developer to edit any PDF using the code above. We can see in the output below how the PDF file with the stamp provides more authenticity, and has numerous opportunities for use in your various .NET project needs.

Without Stamp

With Stamp


Library Quick Access

More API Reference

Get more documentation in the API Reference, providing other watermarking, authenticating, editing, and manipulating capabilities for your C# PDF projects.

More API Reference