1
votes

I have a large HTML document with the background being converted to PDF (using wkhtmltopdf).

Sometimes page break happens in middle of the text block, and last line before page break is too close to the bottom of page. (text blocks have already with page-break: avoid, and spacing between blocks is large enough to keep the block away from the bottom of page)

Is there a possibility to add margin / padding to last line before page break?

1

1 Answers

1
votes

Seems like page-break-inside: avoid might be the source of the problem. According to MDN, https://developer.mozilla.org/en-US/docs/Web/CSS/page-break-inside, it probably causes the text blocks ignore page's margins.

Maybe you could manually place page-break-after: always somewhere in your HTML code so as to achieve the needed formatting. Another thing to try is maybe display: inline-block with the container having white-space: nowrap and the text block having white-space: normal. (Just a hypothesis, though, seems like some experimentation is needed.)