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.
How to Stamp and Watermark a C# PDF
Step 1
1. Install IronPDF to Your Project
Step number one is to install the IronPDF C# PDF Library into your project. Some may find it convenient to download directly while others may wish to navigate NuGet in order to access the Library. Either method is fine for this use, and you can use the software free 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 add the stamp to your document.
In the below example, we have selected a PDF file. Using the “HtmlStamp()”
function, on a note to use ‘BehindExistingPDFContent()’
, the data which we select will get displayed on the BACK of a PDF, like a watermark.
Alternatively, with ‘OnTopOfExisitingPDFContent()’
, we will display the stamp ABOVE the PDF file.
Here is an example of how these functions could be incoporated into your project.
using System.Windows.Forms;
using IronPdf;
namespace stamphtml
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
//PDFs can be edited or amended by Stamping/Watermark new HTML content into the foreground or background.
PdfDocument pdf = PdfDocument.FromFile("sample.pdf");
//Below are the two examples for Behind Text Stamp or Top of PDF Stamp
//In BackgroundStamp, user can set his/her logo as a Watermark.
var BackgroundStamp = new HtmlStamp() { Html = "<img src='logo.png' />", Width = 1000, Height = 50, Opacity = 50, Left = 68, Top = 25, ZIndex = HtmlStamp.StampLayer.BehindExistingPDFContent};
pdf.StampHTML(BackgroundStamp);
//In ForegroundStamp, user can set his/her Text as a Verified.
var ForegroundStamp = new HtmlStamp() { Html = "<h2 style='color:red'>Copyright 2020 IronPDF.com", Width = 50, Height = 50, Opacity = 50, Rotation = -45, ZIndex = HtmlStamp.StampLayer.OnTopOfExistingPDFContent };
pdf.StampHTML(ForegroundStamp);
//We can SaveAs as our Stamping method is completed.
pdf.SaveAs(@"C:\Users\Jugal\Desktop\Stamped.pdf");
}
}
}
using System.Windows.Forms;
using IronPdf;
namespace stamphtml
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
//PDFs can be edited or amended by Stamping/Watermark new HTML content into the foreground or background.
PdfDocument pdf = PdfDocument.FromFile("sample.pdf");
//Below are the two examples for Behind Text Stamp or Top of PDF Stamp
//In BackgroundStamp, user can set his/her logo as a Watermark.
var BackgroundStamp = new HtmlStamp() { Html = "<img src='logo.png' />", Width = 1000, Height = 50, Opacity = 50, Left = 68, Top = 25, ZIndex = HtmlStamp.StampLayer.BehindExistingPDFContent};
pdf.StampHTML(BackgroundStamp);
//In ForegroundStamp, user can set his/her Text as a Verified.
var ForegroundStamp = new HtmlStamp() { Html = "<h2 style='color:red'>Copyright 2020 IronPDF.com", Width = 50, Height = 50, Opacity = 50, Rotation = -45, ZIndex = HtmlStamp.StampLayer.OnTopOfExistingPDFContent };
pdf.StampHTML(ForegroundStamp);
//We can SaveAs as our Stamping method is completed.
pdf.SaveAs(@"C:\Users\Jugal\Desktop\Stamped.pdf");
}
}
}
Imports System.Windows.Forms
Imports IronPdf
Namespace stamphtml
Partial Public Class Form1
Inherits Form
Public Sub New()
InitializeComponent()
'PDFs can be edited or amended by Stamping/Watermark new HTML content into the foreground or background.
Dim pdf As PdfDocument = PdfDocument.FromFile("sample.pdf")
'Below are the two examples for Behind Text Stamp or Top of PDF Stamp
'In BackgroundStamp, user can set his/her logo as a Watermark.
Dim BackgroundStamp = New HtmlStamp() With {
.Html = "<img src='logo.png' />",
.Width = 1000,
.Height = 50,
.Opacity = 50,
.Left = 68,
.Top = 25,
.ZIndex = HtmlStamp.StampLayer.BehindExistingPDFContent
}
pdf.StampHTML(BackgroundStamp)
'In ForegroundStamp, user can set his/her Text as a Verified.
Dim ForegroundStamp = New HtmlStamp() With {
.Html = "<h2 style='color:red'>Copyright 2020 IronPDF.com",
.Width = 50,
.Height = 50,
.Opacity = 50,
.Rotation = -45,
.ZIndex = HtmlStamp.StampLayer.OnTopOfExistingPDFContent
}
pdf.StampHTML(ForegroundStamp)
'We can SaveAs as our Stamping method is completed.
pdf.SaveAs("C:\Users\Jugal\Desktop\Stamped.pdf")
End Sub
End Class
End Namespace
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.
Library Quick Access
More Object Reference
Get more documentation in the Object Reference, providing other watermarking, authenticating, editing, and manipulating capabilities for your C# PDF projects.
More Object Reference