HTML を PDF に変換するために wkhtmltopdf を使用しています。私の懸念は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>
...
スタイル.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;
}
次の結果が得られます。
何か案は?ありがとう!