Stamping HTML Content

IronPDF for Python can overlay HTML content onto existing PDF pages using the HtmlStamper class, allowing you to add logos, images, text, or any other HTML-rendered element on top of or behind page content.

Getting Started

Create an HtmlStamper with your HTML fragment, configure its positioning and appearance properties, load a PdfDocument, and call ApplyStamp to apply the stamp to all pages.

Understanding the Code

  • HtmlStamper(html): Accepts an HTML string — including <img> tags, styled text, or any valid HTML — and creates a stamper object that renders that HTML as an overlay.
  • HorizontalAlignment: Controls the horizontal position of the stamp on the page. Options include Left, Center, and Right.
  • VerticalAlignment: Controls the vertical position. Options include Top, Middle, and Bottom.
  • IsStampBehindContent: When False (default), the stamp appears on top of existing page content. Set to True to render the stamp behind the content, useful for watermarks or background graphics.
  • Opacity: A value from 0 (transparent) to 100 (fully opaque) that controls how visible the stamp is on the page.
  • PdfDocument.FromFile(path): Loads the existing PDF to be stamped.
  • ApplyStamp(stamper): Applies the stamp to all pages of the document and returns the modified PdfDocument.

Learn to edit and stamp PDFs with IronPDF for Python!

Ready to Get Started?
Version: 2026.6 just released
Still Scrolling Icon

Still Scrolling?

Want proof fast?
run a sample watch your HTML become a PDF.