Wicked pdf rendering the last row across two pages
Asked Answered
G

2

3

I am using wicked_pdf to generate pdfs. The problem i am facing is that, sometimes it displays the last row in the page across two pages. Is there a way to tell wicked_pdf to render the row in next page if it can't fit the entire row in that page or set a limit on the number of rows in a page?

Below image is an example of my problem.

Below image is an example of my problem

My options are

render :pdf => file_name,
       :layout => "pdf.html",
       :disposition => "attachment"
Got answered 11/6, 2013 at 14:17 Comment(0)
S
3

Since WickedPDF isn't actually creating a table (just rendering one from the html/css) there aren't many options available - you can try using page-break-inside: avoid; in your css, you may also need to manually break down the sizes of the tables so that the effect of avoiding page breaks isn't too severe.

css:

table, tr, td, th, tbody, thead, tfoot {
    page-break-inside: avoid;
}

That should get you started, at least.

Edit: Here is another question on this subject with some further info: How to avoid page break inside table row for wkhtmltopdf

Sibling answered 11/6, 2013 at 16:6 Comment(6)
I added page-break-inside. But it is still happening.Got
It still happening for me too. :(Hurty
Try updating tyour wkhtml version to at least 0.12.1.Truncated
Did anyone found solution to this problem?Daggna
I just added .avoidPageBreaks { page-break-inside: avoid !important; } to the element I don't want to be broken. In my case was just on table elements. The additional question suggested by Matt provides solution.Scarito
If you want the table to still appear in more than 1 page (so it doesn't leave "empty spaces", just remove from the selector tableShortcoming
S
0

I have had this same problem. There is no easy answer. You have to close the entire table and issue the .page-break (I define .page-break {page-break-before:always} in my css) outside the table. Then, start a new table and continue to render from where you were at. It's not easy! I ended up counting rows, and even checking for size of cell content to get to cell rows, and just closing the table and restarting as needed.

Definitely a limitation of the HTML to PDF process.

Sallie answered 8/5, 2018 at 18:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.