Add Classic Text Headers & Footers
from ironpdf import *

# Initiate PDF Renderer
renderer = ChromePdfRenderer()

# Add a header to every page easily
renderer.RenderingOptions.FirstPageNumber = 1  # use 2 if a cover page will be appended
renderer.RenderingOptions.TextHeader.DrawDividerLine = True
renderer.RenderingOptions.TextHeader.CenterText = "{url}"
renderer.RenderingOptions.TextHeader.Font = FontTypes.Helvetica
renderer.RenderingOptions.TextHeader.FontSize = 12
renderer.RenderingOptions.MarginTop = 25  # create 25mm space for header

# Add a footer too
renderer.RenderingOptions.TextFooter.DrawDividerLine = True
renderer.RenderingOptions.TextFooter.Font = FontTypes.Arial
renderer.RenderingOptions.TextFooter.FontSize = 10
renderer.RenderingOptions.TextFooter.LeftText = "{date} {time}"
renderer.RenderingOptions.TextFooter.RightText = "{page} of {total-pages}"
renderer.RenderingOptions.MarginBottom = 25  # create 25mm space for footer

# Mergeable fields are:
# {page} {total-pages} {url} {date} {time} {html-title} & {pdf-title}
pip install ironpdf
Add Classic Text Headers & Footers

Add Classic Text Headers & Footers

IronPDF for Python makes it easy to add consistent text-based headers and footers to every page of a rendered PDF using the TextHeader and TextFooter properties of RenderingOptions.

Getting Started

Configure TextHeader and TextFooter on a ChromePdfRenderer instance before rendering. Set MarginTop and MarginBottom to create enough space so the headers and footers do not overlap the page content.

Understanding the Code

  • TextHeader: A TextHeaderFooter object that configures the header appearing at the top of every page.
  • TextFooter: A TextHeaderFooter object that configures the footer appearing at the bottom of every page.
  • DrawDividerLine: When True, draws a horizontal line separating the header or footer from the page body.
  • CenterText: The text displayed in the center position. Supports dynamic merge fields.
  • LeftText / RightText: Text aligned to the left and right of the header or footer area.
  • Font / FontSize: Controls the typeface and size of the header/footer text.
  • MarginTop / MarginBottom: Page margins in millimeters. Increase these to reserve space for headers and footers.
  • FirstPageNumber: The starting page number. Set to 2 when a cover page will be prepended to the document.

Dynamic Merge Fields

The following tokens are replaced with live values at render time:

{page} {total-pages} {url} {date} {time} {html-title} {pdf-title}

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

Ready to Get Started?

Version:2026.11just released