wkhtmltopdf page-break-after have whitespace

我是研究僧i 提交于 2019-12-05 02:30:59

问题


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?


回答1:


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




回答2:


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'


来源:https://stackoverflow.com/questions/27058472/wkhtmltopdf-page-break-after-have-whitespace

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!