Stamping New Content

HTML stamping leverages an input HTML fragment, granting control over design through inline CSS styling. In the code below, we include images within the HTML and then stamp them onto the document.

IronPDF offers a variety of versatile stamping options, including HTML, text, images, and barcodes. For each stamp, you can precisely define its position using both vertical and horizontal general locations. These locations can be further adjusted using offsets to achieve pixel-perfect placement. Additionally, most stamp types include opacity and rotation properties.

To learn more about how to effectively use these stamping features, visit the IronPDF Product Features page, where you'll find detailed information on customizing and implementing stamps in your PDF documents.

// Import the IronPDF library
using IronPdf;

class PDFStamper
{
    static void Main()
    {
        // Path to the existing PDF document
        var pdfPath = @"example.pdf";

        // Load an existing PDF document
        var pdfDocument = PdfDocument.FromFile(pdfPath);

        // Define an HTML fragment for the stamp
        // Inline CSS styles are used for customization
        var htmlStamp = "<div style='font-size:12px; color:red;'><img src='stamp-image.png' alt='Stamp Image' width='100' height='50'/><p>Confidential</p></div>";

        // Define the stamp properties
        var stampOptions = new HtmlStampOptions()
        {
            HorizontalAlignment = HorizontalAlignment.Center,
            VerticalAlignment = VerticalAlignment.Top,
            // Offset the stamp by 20 pixels from the top and 10 pixels from the center
            TopOffset = 20,
            HorizontalOffset = 10,
            Opacity = 0.5, // Set the stamp opacity to 50%
            Rotation = 45 // Rotate the stamp by 45 degrees
        };

        // Add the HTML stamp to the document
        pdfDocument.StampHtml(htmlStamp, stampOptions);

        // Save the updated PDF document
        pdfDocument.SaveAs(@"stamped_example.pdf");
    }
}
// Import the IronPDF library
using IronPdf;

class PDFStamper
{
    static void Main()
    {
        // Path to the existing PDF document
        var pdfPath = @"example.pdf";

        // Load an existing PDF document
        var pdfDocument = PdfDocument.FromFile(pdfPath);

        // Define an HTML fragment for the stamp
        // Inline CSS styles are used for customization
        var htmlStamp = "<div style='font-size:12px; color:red;'><img src='stamp-image.png' alt='Stamp Image' width='100' height='50'/><p>Confidential</p></div>";

        // Define the stamp properties
        var stampOptions = new HtmlStampOptions()
        {
            HorizontalAlignment = HorizontalAlignment.Center,
            VerticalAlignment = VerticalAlignment.Top,
            // Offset the stamp by 20 pixels from the top and 10 pixels from the center
            TopOffset = 20,
            HorizontalOffset = 10,
            Opacity = 0.5, // Set the stamp opacity to 50%
            Rotation = 45 // Rotate the stamp by 45 degrees
        };

        // Add the HTML stamp to the document
        pdfDocument.StampHtml(htmlStamp, stampOptions);

        // Save the updated PDF document
        pdfDocument.SaveAs(@"stamped_example.pdf");
    }
}
' Import the IronPDF library
Imports IronPdf

Friend Class PDFStamper
	Shared Sub Main()
		' Path to the existing PDF document
		Dim pdfPath = "example.pdf"

		' Load an existing PDF document
		Dim pdfDocument = PdfDocument.FromFile(pdfPath)

		' Define an HTML fragment for the stamp
		' Inline CSS styles are used for customization
		Dim htmlStamp = "<div style='font-size:12px; color:red;'><img src='stamp-image.png' alt='Stamp Image' width='100' height='50'/><p>Confidential</p></div>"

		' Define the stamp properties
		Dim stampOptions = New HtmlStampOptions() With {
			.HorizontalAlignment = HorizontalAlignment.Center,
			.VerticalAlignment = VerticalAlignment.Top,
			.TopOffset = 20,
			.HorizontalOffset = 10,
			.Opacity = 0.5,
			.Rotation = 45
		}

		' Add the HTML stamp to the document
		pdfDocument.StampHtml(htmlStamp, stampOptions)

		' Save the updated PDF document
		pdfDocument.SaveAs("stamped_example.pdf")
	End Sub
End Class
$vbLabelText   $csharpLabel