How to Handle HTML to PDF Page Breaks Using C#

Add or Avoid Page Breaks in HTML PDFs with C

IronPDF supports page breaks within PDF documents. One major difference between PDF documents and HTML is that HTML documents tend to scroll whereas PDFs are multi-paged and can be printed.

Quickstart: Implementing Page Breaks in HTML to PDF Conversion

Effortlessly convert HTML to PDF with page breaks using IronPDF. This example shows how to insert a page break after specific HTML content to ensure proper pagination. By adding the page-break-after: always; style, developers can control where page breaks occur, enhancing the readability and organization of the resulting PDF document. Perfect for those who need quick, efficient PDF generation from HTML content.

Nuget IconGet started making PDFs with NuGet now:

  1. Install IronPDF with NuGet Package Manager

    PM > Install-Package IronPdf

  2. Copy and run this code snippet.

    new IronPdf.ChromePdfRenderer()
      .RenderHtmlAsPdf("<html><body><h1>Hello World!</h1><div style='page-break-after: always;'></div></body></html>")
      .SaveAs("pageWithBreaks.pdf");
  3. Deploy to test on your live environment

    Start using IronPDF in your project today with a free trial
    arrow pointer


Add a Page Break

To create a page-break in HTML you can use this in your HTML code:

<div style="page-break-after: always;"></div>
<div style="page-break-after: always;"></div>
HTML

Demonstration of Creating a Page Break

In this example, I have the following table and image in my HTML, and I want them to be on two separate pages by adding a page break after the table.

Table

<table style="border: 1px solid #000000">
  <tr>
    <th>Company</th>
    <th>Product</th>
  </tr>
  <tr>
    <td>Iron Software</td>
    <td>IronPDF</td>
  </tr>
  <tr>
    <td>Iron Software</td>
    <td>IronOCR</td>
  </tr>
</table>
<table style="border: 1px solid #000000">
  <tr>
    <th>Company</th>
    <th>Product</th>
  </tr>
  <tr>
    <td>Iron Software</td>
    <td>IronPDF</td>
  </tr>
  <tr>
    <td>Iron Software</td>
    <td>IronOCR</td>
  </tr>
</table>
HTML

Image

<img src="/static-assets/pdf/how-to/html-to-pdf-page-breaks/ironpdf-logo-text-dotnet.svg" style="border:5px solid #000000; padding:3px; margin:5px" />
<img src="/static-assets/pdf/how-to/html-to-pdf-page-breaks/ironpdf-logo-text-dotnet.svg" style="border:5px solid #000000; padding:3px; margin:5px" />
HTML
:path=/static-assets/pdf/content-code-examples/how-to/html-to-pdf-page-breaks-page-break.cs
using IronPdf;

const string html = @"
  <table style='border: 1px solid #000000'>
    <tr>
      <th>Company</th>
      <th>Product</th>
    </tr>
    <tr>
      <td>Iron Software</td>
      <td>IronPDF</td>
    </tr>
    <tr>
      <td>Iron Software</td>
      <td>IronOCR</td>
    </tr>
  </table>

  <div style='page-break-after: always;'> </div>

  <img src='https://ironpdf.com/img/products/ironpdf-logo-text-dotnet.svg'>";

var renderer = new ChromePdfRenderer();

var pdf = renderer.RenderHtmlAsPdf(html);
pdf.SaveAs("Page_Break.pdf");
Imports IronPdf

Private Const html As String = "
  <table style='border: 1px solid #000000'>
    <tr>
      <th>Company</th>
      <th>Product</th>
    </tr>
    <tr>
      <td>Iron Software</td>
      <td>IronPDF</td>
    </tr>
    <tr>
      <td>Iron Software</td>
      <td>IronOCR</td>
    </tr>
  </table>

  <div style='page-break-after: always;'> </div>

  <img src='https://ironpdf.com/img/products/ironpdf-logo-text-dotnet.svg'>"

Private renderer = New ChromePdfRenderer()

Private pdf = renderer.RenderHtmlAsPdf(html)
pdf.SaveAs("Page_Break.pdf")
$vbLabelText   $csharpLabel

And the code above will generate the PDF below, which has 2 pages: the Table on the First page and the Image on the second:

Avoiding Page Breaks in Images

To avoid a page-break within an image or table, you may use the CSS page-break-inside attribute applied to a wrapping DIV element.

<div style="page-break-inside: avoid">
    <img src="no-break-me.png" />
</div>
<div style="page-break-inside: avoid">
    <img src="no-break-me.png" />
</div>
HTML

Avoiding Page Breaks in Tables

As shown above, page breaks within tables can be avoided by using the CSS page-break-inside: avoid. This is better applied to a wrapping DIV than to the table itself to ensure the style is applied to a block-level HTML node.

To duplicate table headers and footers across every page of a large HTML table spanning multiple PDF pages, you may use a <thead> group within the table:

<thead>
    <tr>
        <th>C Sharp</th><th>VB</th>
    </tr>
</thead>
<thead>
    <tr>
        <th>C Sharp</th><th>VB</th>
    </tr>
</thead>
HTML

Advanced CSS3 Settings

To give greater control, you may wish to use CSS3 in addition to your thead group:

<style type="text/css">
    table { page-break-inside:auto }
    tr { page-break-inside:avoid; page-break-after:auto }
    thead { display:table-header-group }
    tfoot { display:table-footer-group }
</style>
<style type="text/css">
    table { page-break-inside:auto }
    tr { page-break-inside:avoid; page-break-after:auto }
    thead { display:table-header-group }
    tfoot { display:table-footer-group }
</style>
HTML

Frequently Asked Questions

How can I add a page break when converting HTML to PDF?

To add a page break when converting HTML to PDF, you can insert a <div style='page-break-after: always;'></div> in your HTML code. This will ensure that the content following the div starts on a new page when using IronPDF.

How do I prevent page breaks within an image in PDF conversion?

To prevent page breaks within an image during PDF conversion, wrap the image in a <div style='page-break-inside: avoid'> using IronPDF. This CSS style ensures the image is not split across pages.

What is the best way to avoid page breaks in HTML tables when generating PDFs?

To avoid page breaks in HTML tables during PDF generation, apply the CSS page-break-inside: avoid to a wrapping <div> element. This ensures the table remains intact on the page when using IronPDF.

How can I ensure table headers repeat on each page in a PDF?

To ensure table headers repeat on each page of a PDF, use a <thead> element in your HTML table. This allows IronPDF to duplicate headers across multiple pages.

What CSS settings can control page breaks in PDF documents?

Advanced CSS settings for controlling page breaks in PDFs include using page-break-inside: auto for tables, page-break-inside: avoid; page-break-after: auto for rows, and setting display: table-header-group for <thead> and display: table-footer-group for <tfoot> when using IronPDF.

How does HTML differ from PDF in terms of page layout?

HTML documents generally scroll continuously, while PDFs are structured as multi-paged documents that require proper pagination. This is managed effectively using IronPDF.

What library can help with adding page breaks in PDFs via C#?

IronPDF is a C# library that can be utilized to manage page breaks when converting HTML to PDF. It offers various settings to handle page breaks efficiently.

Is IronPDF’s page break CSS fully supported in .NET 10 projects?

Yes — IronPDF is fully compatible with .NET 10, and its HTML-to-PDF page-break features (such as page-break-after: always and page-break-inside: avoid) work out of the box in .NET 10 environments. You can install the library via NuGet in a .NET 10 project and use the same CSS-based page-break rules without modifications.

Curtis Chau
Technical Writer

Curtis Chau holds a Bachelor’s degree in Computer Science (Carleton University) and specializes in front-end development with expertise in Node.js, TypeScript, JavaScript, and React. Passionate about crafting intuitive and aesthetically pleasing user interfaces, Curtis enjoys working with modern frameworks and creating well-structured, visually appealing manuals.

...

Read More
Ready to Get Started?
Nuget Downloads 16,227,205 | Version: 2025.11 just released