Page break for long table

John picture John · Mar 21, 2016 · Viewed 8.4k times · Source

I have a long table which shows rows on several pages. When a page ends, the row is printed half on one page and half on the next page. How can I make sure that the rows is printed completely on the new page?

Answer

Patrick Refondini picture Patrick Refondini · Mar 22, 2016

CSS property: page-break-inside: avoid; on HTML tr element does it.

Tested with:
wkhtmltopdf 0.12.3 provided for Linux (Ubuntu Trusty) 32-bit / 64-bit built on Ubuntu 14.04.2 as provided at: http://wkhtmltopdf.org/downloads.html#stable

A quick and dirty test may look like:

<tr style="page-break-inside: avoid;">
  <!-- A little border to see the result more easily -->
  <td style="border: solid 1px blue;">
    Large text possibly displayed on several pages ... 
    Large text possibly displayed on several pages ... 
    Large text possibly displayed on several pages ... 
    Large text possibly displayed on several pages ... 
  </td>
  <td>col2</td>
  <td>col3</td>
</tr>

Mozilla Developer Network page-break-inside description