Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to apply CSS page-break to print a table with lots of rows?

I have a dynamic table in my web page that sometimes contains lots of rows. I know there are page-break-before and page-break-after CSS properties. Where do I put them in my code in order to force page breaking if needed?

like image 401
Mohammad Saberi Avatar asked Jan 03 '12 12:01

Mohammad Saberi


People also ask

How do you insert a page-break in a table?

When you insert a manual page break (Ctrl+Enter) in a table, you split the table, and the empty paragraph is the result. To create a page break without splitting the table (which also allows your heading row(s) to repeat), apply the "Page break before" property to the row you want to appear on a new page.

How do you do a page-break in CSS?

The page-break-after property adds a page-break after a specified element. Tip: The properties: page-break-before, page-break-after and page-break-inside help to define how a document should behave when printed. Note: You cannot use this property on an empty <div> or on absolutely positioned elements.

How do I create a dynamic page-break in HTML?

page-break-before: auto instead of . page-break-before: always. The "auto" will break the page only if the contents are at the end if the page, this will prevent breaking the page and leaving a lot of blank space.


1 Answers

You can use the following:

<style type="text/css">    table { page-break-inside:auto }    tr    { page-break-inside:avoid; page-break-after:auto } </style> 

Refer the W3C's CSS Print Profile specification for details.

And also refer the Salesforce developer forums.

like image 125
Hemant Metalia Avatar answered Sep 28 '22 13:09

Hemant Metalia