Introduction
In every organization, documentation plays a crucial role—Invoices, Delivery Notes, Quotations, Purchase Orders, Payroll Slips, Certificates, Work Orders, and more. While ERPNext provides standard print formats, businesses often require professional, branded, or fully customized outputs to meet customer expectations, legal requirements, and operational standards. This is where Jinja-based print formats in ERPNext become extremely powerful.
ERPNext uses Jinja, a popular templating engine, to build dynamic print formats. With Jinja, you can create intelligent layouts, conditional blocks, loops, tables, signatures, multi-language text, and beautifully structured PDF outputs. Whether you want a simple aligned invoice or a complex manufacturing report with nested tables, Jinja templates give full flexibility.
This blog takes a full deep dive—ideal for beginners and developers who want a complete advanced guide.
Extra Explanation: The introduction sets the stage for understanding how document presentation influences professionalism and operational accuracy. Many companies underestimate the importance of well-structured printed documents until issues arise—incorrect totals displayed, missing tax details, or poorly aligned sections. Advanced print formats solve these challenges by giving businesses complete control over how their outputs look and function. With ERPNext and Jinja working together, even complex documents can be automated, accurate, and visually consistent across all departments.
1. What Are Print Formats in ERPNext?
Print Formats are the templates used to generate official PDF/HTML outputs of ERPNext documents.
- Sales Invoice print
- Purchase Order layout
- Delivery Note transport documents
- HR Payroll slip
- Production Order job card sheets
- POS receipts
- Multi-page certificates
ERPNext supports three types:
- Standard Format
- Custom Format Builder
- Custom Jinja Print Format
Extra Explanation: Print formats ensure that all transactional and operational documents leaving your organization carry the right structure, brand identity, and legal details. While standard templates are good for quick usage, most businesses eventually need customization to match their workflow or country-specific compliance guidelines. Jinja-based formats allow complete flexibility, making it possible to design sophisticated layouts tailored to each department’s needs without affecting underlying system data.
2. Why Use Jinja for Advanced Print Formats?
Jinja print formats let you:
- Apply conditional logic
- Add loops
- Format values
- Apply dynamic content
- Build complex layouts
Extra Explanation: Jinja provides the intelligence layer missing from traditional static print templates. With its logic-powered structure, businesses can automate conditional sections—such as tax breakdowns, discounts, multi-step operations, or special instructions—ensuring that each document adapts to its content. This removes the need for manual editing and guarantees consistency across thousands of documents, especially for high-volume operations like manufacturing or wholesale distribution.
3. Basics of Jinja Syntax Inside ERPNext
You use:
{{ }}for values{% %}for logic{# #}for comments- Filters for formatting
Extra Explanation: Understanding Jinja syntax is the foundation for designing print formats that are both functional and visually clean. The separation between output and logic ensures templates remain easy to read and update. This approach also empowers non-developers, such as ERP consultants or power users, to modify print formats without deep coding knowledge—significantly improving customization speed within ERPNext projects.
4. Understanding the doc Object
The doc object refers to the exact document being printed.
Extra Explanation: The doc object acts as a bridge between system data and the print layout. It contains every field, child table, and metadata entry for the specific document being printed. This means any value visible in the form—customer name, tax details, totals, or item attributes—can be injected directly into the print format. Understanding how to navigate the doc object unlocks the full potential of dynamic document creation in ERPNext.
5. Creating a New Jinja Print Format (Step-by-Step)
Steps:
- Go to Print Format → New → Select Doctype → Choose Jinja → Add code.
Extra Explanation: ERPNext makes print format creation user-friendly by offering an in-system editor where you can write HTML, CSS, and Jinja together. This eliminates dependence on external tools or backend access. Once a Jinja print format is saved, it instantly becomes available for all documents of that type, making it easy to test, adjust, and implement revisions without disrupting daily operations.
6. Building the Basic Structure Using Jinja
Basic HTML + Jinja example.
<div class="invoice">
<h2>{{ doc.company }}</h2>
<p>Date: {{ doc.posting_date }}</p>
<p>Customer: {{ doc.customer_name }}</p>
<table class="table">
<thead>
<tr>
<th>#</th>
<th>Item</th>
<th>Qty</th>
<th>Rate</th>
<th>Amount</th>
</tr>
</thead>
<tbody>
{% for row in doc.items %}
<tr>
<td>{{ loop.index }}</td>
<td>{{ row.item_name }}</td>
<td>{{ row.qty }}</td>
<td>{{ row.rate }}</td>
<td>{{ row.amount }}</td>
</tr>
{% endfor %}
</tbody>
</table>
<h3>Total: {{ doc.rounded_total }}</h3>
</div>
Extra Explanation: The base structure of a print format defines its readability and flow. A well-designed HTML layout ensures proper alignment of items, totals, headers, and footers. Adding Jinja logic on top of this makes the structure dynamic, allowing the same template to adapt to different types of documents, customers, tax configurations, and item quantities without ever needing manual adjustments.
7. Applying Conditional Logic (Advanced)
Show fields only when needed.
{% if doc.discount_amount > 0 %}
<p><strong>Discount Applied:</strong> {{ doc.discount_amount }}</p>
{% endif %}
Extra Explanation: Conditional logic enhances the professionalism of documents by avoiding unnecessary clutter. For example, a discount block will appear only when discounts are applied, or warranty information may only show for specific products. This conditional visibility improves clarity for clients and makes documents cleaner and easier to interpret while still carrying all required details when applicable.
8. Loops, Nested Tables & Child Table Handling
Used for item tables and multi-level data.
{% for operation in doc.operations %}
<h4>{{ operation.operation }}</h4>
{% for step in operation.steps %}
<p>{{ step.step_description }}</p>
{% endfor %}
{% endfor %}
Extra Explanation: Loops enable ERPNext print formats to automatically expand based on the number of items or rows inside child tables. Nested loops allow even more complex structures like Bills of Materials, multi-step operations, or layered costing sheets to be represented clearly. This automation ensures accuracy and saves users from manual formatting each time a document is printed.
9. Formatting Dates, Currency, and Numbers
Use Jinja filters for formatting.
{{ doc.posting_date | frappe.format_date }}
{{ doc.total | frappe.format_value }}
{{ row.rate | round(2) }}
Extra Explanation: Correct formatting is essential for professionalism and compliance. Dates must follow regional formats, currency should show consistent decimal places, and tax values must be precise. Jinja filters enable effortless formatting that aligns with system-wide settings, ensuring every generated PDF maintains accuracy and clarity across financial and operational documents.
10. Adding Company Logo & Branding
Add logo dynamically.
<img src="{{ frappe.db.get_value('Company', doc.company, 'theme_logo') }}" style="height:80px;">
Or default:
{{ frappe.get_print_logo(doc) }}
Extra Explanation: Brand identity plays a critical role in how customers perceive your company. By dynamically embedding the company logo and other brand elements, ERPNext ensures every printed document looks consistent. This approach also simplifies brand management—changing the logo in Company settings automatically updates every print format across the entire ERP system.
11. Dynamic Signatures (Auto Loaded)
Insert signatures based on user or approver.
<p>Approved By:</p>
<img src="{{ doc.owner_signature }}" height="70px">
Or:
<img src="{{ frappe.db.get_value('User', doc.owner, 'digital_signature') }}">
Extra Explanation: Digital signatures remove the need for physical signing and allow documents to be authenticated instantly. ERPNext stores signature files within user profiles, making it easy to automatically embed them in approvals, payroll slips, purchase approvals, and delivery documents. This feature is especially valuable in remote teams and automated workflows.
12. Page Breaks & Multi-Page Layouts
Use CSS page-break logic.
<div style="page-break-after: always;"></div>
Extra Explanation: Page breaks ensure large tables or lengthy documents maintain a clean structure when converted to PDF. Without controlled breaks, important sections may split awkwardly across pages. Proper page-break usage enhances readability, ensures compliance formatting, and helps present long documents—like job cards or QC reports—in a polished and organized way.
13. Advanced Table Designs with Jinja
For complex tax or costing tables.
{% set taxes = frappe.get_doc('Sales Taxes and Charges Template', doc.taxes_and_charges) %}
<table>
<tr><th>Tax</th><th>Rate</th><th>Amount</th></tr>
{% for t in doc.taxes %}
<tr>
<td>{{ t.description }}</td>
<td>{{ t.rate }}%</td>
<td>{{ t.tax_amount }}</td>
</tr>
{% endfor %}
</table>
Extra Explanation: Advanced documents often require detailed breakdowns—multiple tax layers, item-specific costing, or extensive component-level information. Jinja enables complete control over such tables, ensuring they remain readable, aligned, and professionally formatted. This is essential for industries like manufacturing, engineering, and accounting where precision is critical.
14. Adding Conditional Watermarks
Show DRAFT or CANCELLED watermark.
{% if doc.status == "Draft" %}
<div class="watermark">DRAFT</div>
{% endif %}
Extra Explanation: Watermarks act as visual alerts that instantly inform users about a document’s status. This prevents accidental use of draft or cancelled documents during operations or audits. Jinja automates this by checking the document state and applying the appropriate watermark, reducing manual intervention and preventing errors.
15. Using Custom CSS Inside the Print Format
CSS controls layout, spacing, fonts, and table styling.
<style>
.invoice-header { font-size: 20px; font-weight: bold; }
table th { background: #f0f0f0; }
</style>
Extra Explanation: CSS allows you to fine-tune the visual structure of print formats without overcomplicating design. Adjusting padding, table layouts, font sizes, and borders ensures that every document looks polished and readable. While ERPNext restricts overly complex styling to ensure PDF compatibility, enough flexibility is available to produce beautiful and consistent print formats. Well-organized CSS elevates documents to industry-level presentation.
16. Pulling Linked Documents (Very Advanced)
Attach customer or supplier data.
{% set customer = frappe.get_doc("Customer", doc.customer) %}
<p>Customer Mobile: {{ customer.mobile_no }}</p>
Extra Explanation: Linked document data is often necessary for accurate print outputs—for example, including customer phone numbers, shipping addresses, or supplier tax IDs. Jinja enables templates to fetch related data from linked records, ensuring each printed document contains complete and current information directly from the ERP database without duplicating data.
17. Best Practices for Building Print Formats
Keep structure clean and maintainable.
Extra Explanation: Following best practices helps ensure that your print formats remain easy to update and modify in the future. Clean code, consistent naming, and well-organized sections reduce maintenance time and make the template simpler for other team members to understand. This leads to long-term stability and avoids issues during ERPNext upgrades.
18. Common Mistakes to Avoid
Avoid heavy CSS, JS, or broken tags.
Extra Explanation: Many print format problems occur due to complex CSS, missing tags, or unsupported scripts. These issues can break layouts or prevent PDFs from rendering. Avoiding common mistakes ensures print formats function smoothly, especially in environments where high-volume printing is required.
Conclusion
Mastering Jinja print formats unlocks professional, automated document generation within ERPNext. It empowers businesses to create branded, structured PDFs that enhance clarity and improve operational workflows. With the flexibility of Jinja and the power of ERPNext’s data model, organizations can design documents that perfectly match their business needs.

No comments yet. Login to start a new discussion Start a new discussion