Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

wkhtmltopdf is randomly adding extra padding to last row

I am trying to make a PDF of QR codes, but wkhtmltopdf is adding random padding on the last row of the page even though it should fit fine. It renders fine in the browser.

Full code is here: https://jsfiddle.net/pxga201s/2/

The command I use to render it is:

/usr/local/bin/wkhtmltopdf --margin-bottom 0 --margin-left 0 --margin-right 0 --margin-top 0 'file:///path/to/qrcodes-5-6.pdf.html' '/path/to/qrcodes-5-6.pdf'

I am using wkhtmltopdf 0.12.3 (with patched qt) on Mac 10.10.5.

enter image description here When I use:

tr {
    page-break-inside: avoid; 
    page-break-after: auto;
}

it still adds the padding, but just pushes it to the next page:

enter image description here

like image 590
Petah Avatar asked Nov 06 '16 20:11

Petah


1 Answers

If you'll always have 4 <tr> in table you could just do page-break-after: always; on <table> without page break on <tr> elements.

And if you'll have all in one table then you could do something like this (without page break on <table>):

tr:nth-child(4n+5){
    page-break-inside: avoid;
    page-break-after: always;
}

I tested both and it works fine. Even with much more pages.

Update

Full example here https://jsfiddle.net/pxga201s/4/

like image 122
Jakob Avatar answered Sep 28 '22 00:09

Jakob