Search code examples
htmlcssprintingwkhtmltopdf

wkhtmltopdf page-break-after have whitespace


I use WKHTMLTOPDF to generate a PDF from a printer-friendly webpage. I upgraded from version 0.10.0 rc2 to 0.12.1(with patched qt) but now when I use the CSS properties like page-break-before:always; it inserts a bunch of whitespace, and the page-breake-inside:avoid; doesn't work, it's magic.

I use this call:

/usr/local/bin/wkhtmltopdf --encoding 'UTF-8' 'page-to-print' '/tmp/PDFV59OZt'

I have tried with and without both --print-media-type and --no-print-media-type.

When I render the printer-friendly page in my browser, and when I try to print it (before I make it a pdf) it works fine.

examples of my CSS:

//if i want to make a static page-break between two elements
page-break{
    page-break-after:always;
    clear:both;
    display:block;
}
//Avoid cutting images
img{
    display:block;
    page-break-before:auto;
    page-break-after:auto;
    page-break-inside:avoid;
}
//avoid cutting text
p,em,li,span,tr{ 
    page-break-inside:avoid; 
}

Only page-break-after:always; works, but it inserts a bunch of white-space. Does anyone have any ideas for this?


Solution

  • The solution i found was to set the page size to A3, which make all the clever printerfriendly stuff work.

    I use this WKHTMLTOPDF call:

    /usr/local/bin/wkhtmltopdf --page-size 'A3' --encoding 'UTF-8' '<LINK TO PAGE>' '/tmp/PDFX6BefV'