Search code examples
djangoweasyprint

Writing multiple page pdf from html template using weasy print and django


Hi am generating PDF's from html template containing a table which number of rows vary, problem is when the rows are in excess of certain number(12) the rest of the rows plus the footer are pushed further below and don't appear in the generated pdf.How can I make it dynamic so that extra info is pushed to new page each having atleast a certain number of rows, or is there a way weasy print to move data to another page if the current is full

So far I have page breaks on the template but it has worked.

{% for record in data %}
    <tr>
        <td> {{ record.id}}</td>
        <td> {{ record.date}}</td>
    </tr>
    {% if forloop.counter|divisibleby:12 %}
        <div style="page-break-after: always;"></div>
        div style="page-break-before: always;"></div>
    {% endif %}
{% endfor %}

Solution

  • Removed the body tags from my template and it worked without using page breaks, weasyprint limits everything in the body tag to be one document in a page. another answer that helped