Dear ERPNEXT Community,
I have been using ERPNEXT for a few years and have been spending a lot of time on this discussion forum and Google. I know many people are struggling with the customization, and there aren’t always readily available documentation for certain topics. So I would like to contribute to the community as a gratitude for the team and everyone for making this amazing system possible.
In order to get page break and page number on to your print format, please insert the code below into the custom print format for the doctype you want (Sales Order, Sales Invoice, etc):
<table>
<thead>
.......
</thead>
<tbody>
{# Page Number Setting - 1 #}
{% set cnt = [0] %}
{%- for item in doc.items -%}
{% if not item.page_break %}
<tr>
<td> {{item.idx}} </td>
.....
</tr>
{%- else -%}
{# Page Number Setting - 2 #}
{% if cnt.append(cnt.pop() + 1) %}{% endif %}
{# Page Number Setting - 3 #}
{{ "This is page: " }} {{cnt[0]}}
{# Your footer can go here #}
{# Page Break #}
<div class="page-break"></div>
{{ add_header(0,1,doc,letter_head, no_letterhead) }}
{# Repeat your header code from above here with invoice number, customer names etc #}
<table style="width:100%; position: sticky; border: 1px solid; margin-top: -1px;">
<thead>
......
</thead>
<tbody>
<tr>
<td> {{item.idx}} </td>
....
</tr>
{%- endif -%}
{%- endfor -%}
</tbody>
</table>
{# Page Number Setting - 4 #}
{% set total_page = cnt[0] + 1 %}
{{ "This is page: "}} {{ total_page }} / {{ total_page }}
{# Your footer goes here #}
For your footer, depending on its size, it should be a table with following CSS class (Put this in the CSS Column below the print format):
.footer {
position: fixed;
bottom: 0;
right: 0;
width: 100%;
border-collapse: collapse;
min-height: 30mm; #Enter the height you want
}
I understand that the footer solution is not very elegant but it works. Keep in mind that there are two places that the footer table have to go in, and they both have to be EXACTLY the same, or there will be mismatched printing on the screen.
I hope this helps out anyone who’s having trouble with this.