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.6 just released
Still Scrolling Icon

Still Scrolling?

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