我正在使用 wkhtmltopdf 将我的 HTML 转换为 PDF。我担心的是page-break-* : ignore;
指令。我试图阻止 PDF 在标题(以及其他)之后立即剪切到新页面,因此标题和内容总是粘在一起。不知何故,它似乎真的不起作用!我尝试了许多不同的方式,但结果总是一样的,忽略 CSS ......任何page-break-inside: avoid !important;
,page-break-after: avoid !important;
或page-break-before: avoid !important;
似乎都有效。
编辑:
我的代码示例是:
索引.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>
...
样式.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;
}
给出以下结果:
有任何想法吗?谢谢!