IRONSOFTWAREHOME
Add HTML Headers & Footers
from ironpdf import *
import os

# Instantiate Renderer
renderer = ChromePdfRenderer()
 
# Build a footer using html to style the text
# mergeable fields are:
# {page} {total-pages} {url} {date} {time} {html-title} & {pdf-title}
renderer.RenderingOptions.HtmlFooter = HtmlHeaderFooter()
renderer.RenderingOptions.HtmlFooter.MaxHeight = 15  # millimeters
renderer.RenderingOptions.HtmlFooter.HtmlFragment = "<center><i>{page} of {total-pages}<i></center>"
renderer.RenderingOptions.HtmlFooter.DrawDividerLine = True
 
# Use sufficient MarginBottom to ensure that the HtmlFooter does not overlap with the main PDF page content.
renderer.RenderingOptions.MarginBottom = 25  # mm
 
# Build a header using an image asset
# Note the use of BaseUrl to set a relative path to the assets
renderer.RenderingOptions.HtmlHeader = HtmlHeaderFooter()
renderer.RenderingOptions.HtmlHeader.MaxHeight = 20  # millimeters
renderer.RenderingOptions.HtmlHeader.HtmlFragment = "<img src='iron.png'>"
renderer.RenderingOptions.HtmlHeader.BaseUrl = os.path.abspath("C:/Users/lyty1/OneDrive/Documents/IronPdfPythonNew")

# Use sufficient MarginTop to ensure that the HtmlHeader does not overlap with the main PDF page content.
renderer.RenderingOptions.MarginTop = 25  # mm
pip install ironpdf
Add HTML Headers & Footers

Add HTML Headers & Footers

IronPDF for Python supports fully styled HTML headers and footers, letting you use any combination of HTML and CSS - including images, custom fonts, and dynamic merge fields - in the header and footer areas of your PDF.

Getting Started

Create HtmlHeaderFooter objects and assign them to RenderingOptions.HtmlHeader and RenderingOptions.HtmlFooter. Set MaxHeight to limit the height of each area and configure MarginTop / MarginBottom to prevent overlap with the page body.

Understanding the Code

  • HtmlHeaderFooter: An object that accepts an HTML fragment and renders it as the header or footer on every page.
  • HtmlFragment: The HTML content to display. Dynamic merge fields such as {page} and {total-pages} are supported within the HTML.
  • MaxHeight: The maximum height in millimeters that the header or footer area can occupy.
  • DrawDividerLine: When True, draws a horizontal rule between the header/footer and the page content.
  • BaseUrl: A base path used to resolve relative asset paths (such as images) in the HTML fragment. Use os.path.abspath to construct an absolute path.
  • MarginTop / MarginBottom: Page margins in millimeters. Ensure these are at least as large as MaxHeight to prevent the header or footer from overlapping body content.

Supported HTML in Headers and Footers

Any HTML that renders correctly in a browser can be used, including <img> tags, <table> layouts, inline styles, and Google Fonts links.

Learn to add headers and footers to PDFs with IronPDF for Python!

Ready to Get Started?

Version:2026.8just released

Key in blue circle

Get your free 30-day Trial Key instantly.

Your trial license will be sent to your email address

No limitations. 100% unlocked. No credit card.

bullet_checkedNo credit card or account creation requiredNo limitations. 100% unlocked. No credit card.
  • Logo Aetna
  • Logo NASA
  • Logo GE
  • Logo Porsche
  • Logo USDA
  • Logo Qatar
Join Millions of Engineers who’ve tried IronPDF
Book your free Live Demo
Booking Badge

Trusted by Millions of Engineers Worldwide

Iron Software's customer logos
Get Your No-Obligation Consult
Complete the form below or email sales@ironsoftware.com
Your details will always be kept confidential.
Trusted by Millions of Engineers Worldwide
Iron Software's customer logos
Get your free 30-day Trial Key instantly.
No credit card or account creation required