This is by far the easiest and most reliable way to handle multi-page table printing that I know of. If you just want to take control of your table's row height, though, you can do that with CSS. The CSS below will ensure that the only things affecting the height of your rows are 1) the height of the cell content, and 2) the thickness of the horizontal cell borders (and I'm assuming there isn't any other CSS or relevant HTML attributes that you haven't told us about):
<style>
table {
border-collapse: collapse;
/*^^^ merges adjacent cell and table borders (so table height != sum of row heights!)*/
border-spacing: 0 0; /*removes space between cells*/
-webkit-border-vertical-spacing: 0;
/*^^^ removes Chrome's border-spacing (sort of redundant with border-spacing: 0 0;)*/
}
table > thead {
vertical-align: bottom;
/*^^^ affects the height of rows that get broken by page breaks*/
}
table > tbody {
vertical-align: top;
/*^^^ affects the height of rows that get broken by page breaks*/
}
table > * > * > td,
table > * > * > th {
border: 1px solid black;
padding-top: 0; /*cancels out browser's default cell padding*/
padding-bottom: 0; /*cancels out browser's default cell padding*/
}
</style>
That won't necessarily prevent your last row from getting split by a page break, though. If you're trying to predict how many rows you can squeeze onto a page, you should probably give up on that approach for the following reasons:
- You can't control paper size.
- You can't control paper orientation.
- You can't reliably control margin size.
- Print rendering works differently in different browsers, so content that fits on one page in Firefox or IE may require two pages in Chrome.
If you really want to solve these problems, you should consider using the solution I linked at the top of this post.