Your guide to creating print formats!
# Creating beautiful print formats in ERPNext.
ERPNext is a beautiful software and many organizations use it. And print formats are really important to organizations as hardcopy of every document with their letterhead is a core requirement. Recreating their template in ERPNext is an art and not easy.
I’ll break down the process to make it easy for all the beginners.
ERPNext uses Jinja templating for this purpose. I’m not going to give you a deep explanatory course on Jinja, but the basics that you’ll need for a neat, aesthetic template.
When the client gives you their existing template, you should make a thorough observation of it.
## First off, we split the template into 3 parts: Above, Middle and Below.
1. Above: The above part includes all the static items in the page including the letter head, the customer details and the head of the table(if any).
2. Middle: This part consists of recurring things in the template. Eg: the rows in the table.
3. Bottom: This part consists of static items in the bottom half of the template, including the footer of the table, other calculations and footer of the template.
Now that we have divided the template into three parts. It becomes fairly easier for us to do things and also makes the code look beautiful(you’ll understand how as you keep reading).
We will now use macros for the above and bottom sections/parts. Macros are pieces of code defined by a name. And hence, you can call them just by that name whenever you need them(like functions).
This file has been truncated. show original
6 Likes
sanjay
August 19, 2020, 3:43pm
2
Good attempt. Just would like to suggest below :
You should name sections as Header, Body and Footer.
TBody tag should open and close in middle section.
Thank you for the valuable feedback! I will change the names accordingly for better understanding.
And I kept the opening and closing of tbody in above and below sections to reduce the number of lines of code; it can easily be moved to the middle section
Will modify and add more features once I get some free time.
Thank you once again!
rmeyer
August 20, 2020, 9:28am
4
Thanks for sharing. What are these empty if-statements for?
{% if pr[-1] %} {% endif %}
{% if pr.append( pr[-1] + 1 ) %}{% endif %}
You’re welcome!
It is to overcome a limitation of Jinja’s scope issue. Directly setting them threw error, so I had to do this as a work around for adjusting the value.
Can we achieve different header for first page, and different footer in the last page?
Yes, it is achievable. If you create a detailed issue on GitHub, I’ll add it to the readme on next update.
Dears, in this format how to reduce the table row hieght? it is too big which reducing the number of rows in the invoice per page.