IRONSOFTWAREHOME
Page Numbers and Page Breaks
from ironpdf import *

html = """
    <p> Hello Iron</p>
    <p> This is 1st Page </p>
    <div style='page-break-after: always;'></div>
    <p> This is 2nd Page</p>
    <div style='page-break-after: always;'></div>
    <p> This is 3rd Page</p>
"""

# Instantiate Renderer
renderer = ChromePdfRenderer()

# Configure footer setting
footer = HtmlHeaderFooter()
footer.MaxHeight = 15  # millimeters
footer.HtmlFragment = "<center><i>{page} of {total-pages}</i></center>"
footer.DrawDividerLine = True

renderer.RenderingOptions.HtmlFooter = footer

pdf = renderer.RenderHtmlAsPdf(html)
pdf.SaveAs("pageNumber.pdf")
pip install ironpdf
Page Numbers and Page Breaks

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.9just 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.

OR
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 Iron Suite
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
Python Module Download for PDF
Install with pip

Version: 2026.9

  1. Download and install Python 3.7+.
  2. Install pip from pypi.org if it isn't installed already.
  3. Execute the above command in the terminal.
Python PDF Module
Download Module

Version: 2026.9

Manually install into your project

  1. Download the package
  2. Run this command from the terminal
    pip install ironpdf-2026.9-py37-none-win_amd64.whi

Licenses from $999