Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 %}
like image 885
StackEdd Avatar asked Oct 18 '25 14:10

StackEdd


2 Answers

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

like image 83
StackEdd Avatar answered Oct 21 '25 06:10

StackEdd


I've thrown together a repo to try and reproduce your issue here, and was unable to.

There's a small syntax error in your question - you're missing the < off your second <div />, but apart from that, it all looks good.

like image 30
Adam Barnes Avatar answered Oct 21 '25 07:10

Adam Barnes