问题描述
我使用 WKHTMLTOPDF
从易于打印的网页上生成 PDF 。
我从版本 0.10.0 rc2 升级到了 0.12.1 (带有修补的qt),但是现在当我使用 CSS
属性,例如 page-break-before:always;
会插入一堆空白,并且 page-breake-inside:avoid;
不起作用,这很神奇。
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.
我使用此调用:
/usr/local/bin/wkhtmltopdf --encoding 'UTF-8' 'page-to-print' '/tmp/PDFV59OZt'
我尝试过同时使用和不使用 --print-media类型
和-无打印介质类型
。
I have tried with and without both --print-media-type
and --no-print-media-type
.
当我在我的浏览器中呈现易于打印的页面,当我尝试打印该页面时(在将其制成pdf文件之前),它可以正常工作。
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.
我的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?
推荐答案
我发现的解决方案是将页面大小设置为A3,
The solution i found was to set the page size to A3, which make all the clever printerfriendly stuff work.
我使用此WKHTMLTOPDF调用:
I use this WKHTMLTOPDF call:
/usr/local/bin/wkhtmltopdf --page-size 'A3' --encoding 'UTF-8' '<LINK TO PAGE>' '/tmp/PDFX6BefV'
这篇关于wkhtmltopdf分页后有空白的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!