3

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?

Luiso
  • 4,173
  • 2
  • 37
  • 60
DalekSall
  • 385
  • 1
  • 2
  • 12

2 Answers2

3

I am using version wkhtmltopdf 0.12.0

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

I had to make a special css file for print media to get it work.

Setting the paper size to 'A3' or using the 'overflow: visible' didn't make any difference.

Also see WKHTMLTOPDF with pdfkit on Rails ignoring table page breaks

Community
  • 1
  • 1
1

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'
DalekSall
  • 385
  • 1
  • 2
  • 12