Skip to content

Instantly share code, notes, and snippets.

@mtalcott
Created May 21, 2015 00:28
Show Gist options
  • Save mtalcott/67df9917438308f55eaa to your computer and use it in GitHub Desktop.
Save mtalcott/67df9917438308f55eaa to your computer and use it in GitHub Desktop.
wkthmltopdf 0.12.2.1 page-break rule issues with floating parent elements

test_breaks1.html

Command: wkhtmltopdf test_breaks1.html test_breaks1.pdf

Output: https://mack-public.s3.amazonaws.com/wkhtmltopdf/test_breaks1.pdf

As expected, three separate pages are generated, since paragraph 1 has page-break-after: always and paragraph 3 has page-break-before: always.

test_breaks2.html

Command: wkhtmltopdf test_breaks2.html test_breaks2.pdf

Output: https://mack-public.s3.amazonaws.com/wkhtmltopdf/test_breaks2.pdf

Simply adding a float: left rule to the parent element makes all page-break-* rules for elements within ignored.

<html>
<head>
<title>wkhtmltopdf - test page breaks</title>
</head>
<body>
<div>
<p style="page-break-after: always;">1</p>
<p>2</p>
<p style="page-break-before: always;">3</p>
</div>
</body>
</html>
<html>
<head>
<title>wkhtmltopdf - test page breaks</title>
</head>
<body>
<div style="float: left;">
<p style="page-break-after: always;">1</p>
<p>2</p>
<p style="page-break-before: always;">3</p>
</div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment