WeasyPrint always generating single-page PDFs from Zurb Ink
Asked Answered
A

1

13

Generating a PDF from an email (Zurb Ink templated); but am always presented with a single page PDF.

Runnable test-case:

from weasyprint import HTML, CSS
from urllib2 import urlopen

if __name__ == '__main__':
    html = urlopen('http://zurb.com/ink/downloads/templates/basic.html').read()
    html = html.replace('<p class=\"lead\">', '{0}<p class=\"lead\">'.format(
        '<p class=\"lead\">{0}</p>'.format("foobar " * 50) * 50))
    HTML(string=html).write_pdf('foo.pdf', stylesheets=[
                                  CSS(string='@page { size: A4; margin: 2cm };'
                                             '* { float: none !important; };'
                                             '@media print { nav { display: none; } }')
                                ])

How do I get a multi-page PDF?

Algebraist answered 27/5, 2014 at 3:22 Comment(0)
P
45

Updated Answer:

Try adding this whenever you wish to have a page-break in your document.

<p style="page-break-before: always" ></p>

Old Answer:

<body>
<!-- this is the container div -->
  <div>
    Content
  </div>
</body>

If your html has the above structure then weasyprint will try to fit all of your 'container'content in one page.

First solution I have in mind right now: split your html in 2 separate div-s. Each div should be no longer than the page size.

Papua answered 21/6, 2014 at 14:21 Comment(5)
<p style="page-break-before: always" ></p> worked for meJennettejenni
<p style="page-break-before: always" ></p> - this worked for me as well, thanks a lot.Blistery
You saved my day! Thanks!Spencer
It's didnt works to me,, my height tag depend on parameter i give in render_template(x, yyy)Valgus
You saved my life! Thanks for the update!Dunseath

© 2022 - 2024 — McMap. All rights reserved.