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.

// Example C# code using IronPDF to render an HTML document to PDF with page numbers

using IronPdf;

public class HtmlToPdfExample
{
    public static void Main()
    {
        // Initialize a Renderer for PDF creations
        var renderer = new HtmlToPdf();

        // Set footer with page numbers displayed
        renderer.PrintOptions.Footer = new HtmlHeaderFooter()
        {
            HtmlFragment = "<center>{page} of {total-pages}</center>",
            Height = 15 // Maximum height for footer
        };

        // Convert HTML content to PDF and save to a file
        var pdfDocument = renderer.RenderHtmlAsPdf("<html><body><h1>Page Title</h1><p>Sample page content.</p></body></html>");
        pdfDocument.SaveAs("output.pdf");

        // Confirmation message
        System.Console.WriteLine("PDF with page numbers generated successfully!");
    }
}
// Example C# code using IronPDF to render an HTML document to PDF with page numbers

using IronPdf;

public class HtmlToPdfExample
{
    public static void Main()
    {
        // Initialize a Renderer for PDF creations
        var renderer = new HtmlToPdf();

        // Set footer with page numbers displayed
        renderer.PrintOptions.Footer = new HtmlHeaderFooter()
        {
            HtmlFragment = "<center>{page} of {total-pages}</center>",
            Height = 15 // Maximum height for footer
        };

        // Convert HTML content to PDF and save to a file
        var pdfDocument = renderer.RenderHtmlAsPdf("<html><body><h1>Page Title</h1><p>Sample page content.</p></body></html>");
        pdfDocument.SaveAs("output.pdf");

        // Confirmation message
        System.Console.WriteLine("PDF with page numbers generated successfully!");
    }
}
' Example C# code using IronPDF to render an HTML document to PDF with page numbers

Imports IronPdf

Public Class HtmlToPdfExample
	Public Shared Sub Main()
		' Initialize a Renderer for PDF creations
		Dim renderer = New HtmlToPdf()

		' Set footer with page numbers displayed
		renderer.PrintOptions.Footer = New HtmlHeaderFooter() With {
			.HtmlFragment = "<center>{page} of {total-pages}</center>",
			.Height = 15
		}

		' Convert HTML content to PDF and save to a file
		Dim pdfDocument = renderer.RenderHtmlAsPdf("<html><body><h1>Page Title</h1><p>Sample page content.</p></body></html>")
		pdfDocument.SaveAs("output.pdf")

		' Confirmation message
		System.Console.WriteLine("PDF with page numbers generated successfully!")
	End Sub
End Class
$vbLabelText   $csharpLabel

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.