IRONSOFTWAREHOME
Page Numbers and Page Breaks
import {PdfDocument} from "@ironsoftware/ironpdf";

(async () => {
    const 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>
    `;

    // Configure render options
    const options = {
        htmlHeader: {
            htmlFragment: "<center><i>{page} of {total-pages}<i></center>",
            dividerLine: true,
            maxHeight: 15,
        }
    };

    const pdf = await PdfDocument.fromHtml(html, {renderOptions: options});

    // Save the PDF
    await pdf.saveAs("pageNumber.pdf");
})();
npm i @ironsoftware/ironpdf
Page Numbers and Page Breaks

Page Numbers and Page Breaks

Page breaks in HTML work perfectly when rendering to PDF using IronPDF.

In HTML, a page break is a marker or instruction that tells a web browser or a rendering engine to start a new page when displaying or printing content. Page breaks are typically used when you want to control the layout of printed documents or ensure that certain content starts on a fresh page.

Furthermore, the code below configures rendering options to include the page number at the bottom center of the PDF document. The page number is displayed in the format "{page} of {total-pages}" and is limited to a maximum height of 15 units.

For more information on how to efficiently manage page breaks while converting HTML to PDF, refer to the comprehensive guide on IronPDF features. IronPDF is part of a suite of powerful tools provided by Iron Software tailored for various file processing needs, including barcode generation with IronBarcode, Excel manipulation through IronXL, and optical character recognition with IronOCR.

Explore Code Examples for Page Numbers & Breaks in PDFs
View on GitHub

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.

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
Node.js Module Download for PDF
Install with npm

Version: 2026.8

  1. Download and install Node.js 12+.
  2. Execute the above command in the terminal.

Licenses from $999