Wkhtmltopdf page-break-after have spaces

I am using WKHTMLTOPDF

to generate a PDF from a printable webpage. I have updated version 0.10.0 of rc2 to 0.12.1 (with fixed qt), but now when I use properties CSS

like page-break-before:always;

it inserts a bunch of whitespace page-breake-inside:avoid;

instead of working it's magic.

I am using this call:

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

      

I've tried with and without both --print-media-type

and --no-print-media-type

.

When I create a printable page in my browser and when I try to print it (before I pdf it) 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; 
}

      

Page break only: always; works, but it inserts a bunch of white space. Anyone have any ideas for this?

+3


source to share


2 answers


The solution I found was to set the page size to A3, which makes all the smart printer jobs work.

I am using this WKHTMLTOPDF call:



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

      

+1


source


I am using wkhtmltopdf version 0.12.0

For me, page breaks work ONLY with --print-media-type. Without it, page break protection for images works, but not page breaks or before.

I had to create a custom printable css file for it to work.



Setting the paper size to "A3" or using "overflow: visible" makes no difference.

Also see WKHTMLTOPDF with pdfkit on Rails ignoring page breaks

+3


source







All Articles