我正在使用wkhtmltopdf将HTML转换为PDF。我担心的是page-break-* : ignore;
指令。我试图防止PDF在标题(包括其他标题)之后立即剪切到新页面,因此标题和内容始终粘在一起。不知何故,它似乎真的不起作用!我尝试了许多不同的方法,但是结果始终是相同的,忽略了CSS ... page-break-inside: avoid !important;
,page-break-after: avoid !important;
或page-break-before: avoid !important;
中的任何一个似乎都可以工作。
修改:
我的代码示例为:
index.html
...
<h2>HEADING</h2>
<div class="toctree-wrapper compound"></div>
<p>content content content content content content content
content content content content content content content content
content content content content content content content content
content content content content content content content content
content content content content content content content content
content content content </p>
...
style.css
...
p{
background: green !important; /* color to see where it breaks */
page-break-before: avoid !important;
}
h1, h2, h3, h4, h5, h6{
background: blue !important; /* color to see where it breaks */
page-break-after: avoid !important;
page-break-inside: avoid !important;
}
.toctree-wrapper.compound{
background: pink !important; /* color to see where it breaks */
page-break-after: avoid !important;
page-break-inside: avoid !important;
page-break-before: avoid !important;
}
给出以下结果:
有什么想法吗?谢谢!