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 includeLeft,Center, andRight.VerticalAlignment: Controls the vertical position. Options includeTop,Middle, andBottom.IsStampBehindContent: WhenFalse(default), the stamp appears on top of existing page content. Set toTrueto 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 modifiedPdfDocument.






