Page Numbers and Page Breaks

IronPDF for Python supports automatic page numbering via HTML footers and explicit page breaks via CSS page-break-after directives, giving you precise control over how multi-page documents are structured.

Getting Started

Use the CSS property page-break-after: always in your HTML to force a new page at any point in the content. Pair this with an HtmlHeaderFooter footer configured with {page} and {total-pages} merge fields to automatically number every page.

Understanding the Code

  • page-break-after: always: A CSS rule placed inside a <div> that forces the content following it onto a new page. This is the standard way to create multi-page PDFs from a single HTML string.
  • HtmlHeaderFooter: An object that renders an HTML fragment as the footer on every page. Assign it to RenderingOptions.HtmlFooter.
  • HtmlFragment: The HTML content of the footer. In this example, {page} of {total-pages} is centered in italic text.
  • MaxHeight: Limits the footer area height in millimeters.
  • DrawDividerLine: When True, adds a horizontal separator above the footer.
  • RenderHtmlAsPdf(html): Renders the full multi-page HTML, applying the footer to each page automatically.

Available Page Merge Fields

{page} — current page number
{total-pages} — total number of pages in the document

Learn to create multi-page 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.