Test in production without watermarks.
Works wherever you need it to.
Get 30 days of fully functional product.
Have it up and running in minutes.
Full access to our support engineering team during your product trial
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
Further Reading: How to Stamp Text & Image on PDFs