frappe-printing-templates

Frappe Printing & Templates

Safety Notice

This listing is imported from skills.sh public index metadata. Review upstream SKILL.md and repository scripts before running.

Copy this and send it to your AI assistant to learn

Install skill "frappe-printing-templates" with this command: npx skills add lubusin/agent-skills/lubusin-agent-skills-frappe-printing-templates

Frappe Printing & Templates

Create print formats, email templates, and document templates using Jinja in Frappe.

When to use

  • Creating custom print formats for documents

  • Building email templates with dynamic content

  • Generating PDFs from documents

  • Using Jinja templating in web pages

  • Configuring letter heads for branding

  • Using the Print Format Builder

Inputs required

  • Target DocType for the print format

  • Layout requirements (fields, tables, headers)

  • Whether format is standard (version controlled) or custom (DB-stored)

  • Letter Head / branding requirements

  • PDF generation needs

Procedure

  1. Choose format type

Type How to Create Version Controlled Customizable by User

Standard Developer Mode, saved as JSON Yes No

Print Format Builder Drag-and-drop UI No (DB) Yes

Custom HTML (Jinja) Type "new print format" in awesomebar Optional Depends

  1. Create a Jinja print format

Create via awesomebar → "New Print Format":

  • Set a unique name

  • Link to the target DocType

  • Set "Standard" = "No" (or "Yes" for dev mode export)

  • Check "Custom Format"

  • Set Print Format Type = "Jinja"

  • Write your Jinja HTML

<div class="print-format"> <h1>{{ doc.name }}</h1> <p><strong>{{ _("Customer") }}:</strong> {{ doc.customer }}</p> <p><strong>{{ _("Date") }}:</strong> {{ frappe.format_date(doc.transaction_date) }}</p>

&#x3C;table class="table table-bordered">
    &#x3C;thead>
        &#x3C;tr>
            &#x3C;th>{{ _("Item") }}&#x3C;/th>
            &#x3C;th>{{ _("Qty") }}&#x3C;/th>
            &#x3C;th class="text-right">{{ _("Rate") }}&#x3C;/th>
            &#x3C;th class="text-right">{{ _("Amount") }}&#x3C;/th>
        &#x3C;/tr>
    &#x3C;/thead>
    &#x3C;tbody>
        {% for item in doc.items %}
        &#x3C;tr>
            &#x3C;td>{{ item.item_name }}&#x3C;/td>
            &#x3C;td>{{ item.qty }}&#x3C;/td>
            &#x3C;td class="text-right">{{ frappe.format(item.rate, {'fieldtype': 'Currency'}) }}&#x3C;/td>
            &#x3C;td class="text-right">{{ frappe.format(item.amount, {'fieldtype': 'Currency'}) }}&#x3C;/td>
        &#x3C;/tr>
        {% endfor %}
    &#x3C;/tbody>
    &#x3C;tfoot>
        &#x3C;tr>
            &#x3C;td colspan="3" class="text-right">&#x3C;strong>{{ _("Total") }}&#x3C;/strong>&#x3C;/td>
            &#x3C;td class="text-right">&#x3C;strong>{{ frappe.format(doc.grand_total, {'fieldtype': 'Currency'}) }}&#x3C;/strong>&#x3C;/td>
        &#x3C;/tr>
    &#x3C;/tfoot>
&#x3C;/table>

{% if doc.terms %}
&#x3C;div class="terms">
    &#x3C;h4>{{ _("Terms &#x26; Conditions") }}&#x3C;/h4>
    &#x3C;p>{{ doc.terms }}&#x3C;/p>
&#x3C;/div>
{% endif %}

</div>

<style> .print-format { font-family: Arial, sans-serif; } .print-format h1 { color: #333; } .print-format table { width: 100%; margin-top: 20px; } </style>

  1. Use Frappe Jinja API

Data fetching in templates:

{# Fetch a document #} {% set customer = frappe.get_doc('Customer', doc.customer) %} {{ customer.customer_name }}

{# List query (ignores permissions) #} {% set open_orders = frappe.get_all('Sales Order', filters={'customer': doc.customer, 'status': 'To Deliver and Bill'}, fields=['name', 'grand_total'], order_by='creation desc', page_length=5) %}

{# Permission-aware list query #} {% set my_tasks = frappe.get_list('Task', filters={'owner': frappe.session.user}) %}

{# Single value lookup #} {% set company_abbr = frappe.db.get_value('Company', doc.company, 'abbr') %}

{# Settings value #} {% set timezone = frappe.db.get_single_value('System Settings', 'time_zone') %}

Formatting:

{{ frappe.format(50000, {'fieldtype': 'Currency'}) }} {{ frappe.format_date('2025-01-15') }} {{ frappe.format_date(doc.posting_date) }}

Session and context:

{{ frappe.session.user }} {{ frappe.get_fullname() }} {{ frappe.lang }} {{ _("Translatable string") }}

URLs:

<a href="{{ frappe.get_url() }}/app/sales-order/{{ doc.name }}">View Order</a>

  1. Build email templates

Dear {{ doc.customer_name }},

Your order {{ doc.name }} has been confirmed.

Items: {% for item in doc.items %}

  • {{ item.item_name }} x {{ item.qty }} {% endfor %}

Total: {{ frappe.format(doc.grand_total, {'fieldtype': 'Currency'}) }}

Thank you, {{ frappe.get_fullname() }}

  1. Generate PDFs programmatically

import frappe

Generate PDF

pdf_content = frappe.get_print( doctype="Sales Invoice", name="SINV-001", print_format="Custom Invoice", as_pdf=True )

Attach PDF to document

frappe.attach_print( doctype="Sales Invoice", name="SINV-001", print_format="Custom Invoice", file_name="invoice.pdf" )

Send with email

frappe.sendmail( recipients=["customer@example.com"], subject="Your Invoice", message="Please find attached your invoice.", attachments=[{ "fname": "invoice.pdf", "fcontent": pdf_content }] )

  1. Configure Letter Head
  • Navigate to Letter Head list → New

  • Upload company logo and header image

  • Set as default for the company

  • Letter Head appears automatically on print formats

  1. Use Jinja filters

{{ doc.customer_name|upper }} {# UPPERCASE #} {{ doc.notes|truncate(100) }} {# Truncate text #} {{ doc.description|striptags }} {# Remove HTML #} {{ doc.html_content|safe }} {# Render raw HTML (trusted only!) #} {{ items|length }} {# Count items #} {{ items|first }} {# First item #} {{ names|join(', ') }} {# Join list #} {{ amount|round(2) }} {# Round number #} {{ value|default('N/A') }} {# Default if undefined #} {{ data|tojson }} {# Convert to JSON #}

  1. Template inheritance and macros

{# macros/fields.html #} {% macro field_row(label, value) %} <tr> <td class="label"><strong>{{ _(label) }}</strong></td> <td>{{ value }}</td> </tr> {% endmacro %}

{# In print format #} {% from "macros/fields.html" import field_row %} <table> {{ field_row("Customer", doc.customer_name) }} {{ field_row("Date", frappe.format_date(doc.posting_date)) }} {{ field_row("Total", frappe.format(doc.grand_total, {'fieldtype': 'Currency'})) }} </table>

Verification

  • Print format renders correctly in Print View

  • All fields display with proper formatting

  • PDF generation works without errors

  • Email templates render with correct data

  • Letter Head appears on printed documents

  • Translations work in templates (_() )

  • No XSS risks from unescaped content

Failure modes / debugging

  • Template syntax error: Check Jinja delimiters ({{ }} , {% %} ); look for unclosed blocks

  • Field not rendering: Verify field name matches DocType schema; check child table access pattern

  • PDF generation fails: Check wkhtmltopdf installation; verify print format Jinja is valid

  • Styling issues in PDF: Use inline styles; avoid complex CSS; test with Print View first

  • Permission error in template: Use frappe.get_all (no permission check) vs frappe.get_list

Escalation

  • For app-level hooks and structure → frappe-app-development

  • For DocType schema questions → frappe-doctype-development

References

  • references/jinja.md — Jinja templating and Frappe Jinja API

  • references/printing.md — Print formats and PDF generation

Guardrails

  • Test with actual data: Always preview with real documents; edge cases break templates

  • Handle missing fields gracefully: Use {{ doc.field or '' }} or {% if doc.field %}

  • Use get_url() for images: Never hardcode URLs; use {{ frappe.utils.get_url() }}/files/...

  • Escape user content: Use {{ value | e }} for user-generated content to prevent XSS

  • Keep styling inline: PDF generators don't support external CSS; use inline style attributes

Common Mistakes

Mistake Why It Fails Fix

Wrong Jinja syntax Template error, blank output Use {{ }} for output, {% %} for logic; check closing tags

Missing filters Raw data displayed Use frappe.format() or frappe.format_date() for formatting

Hardcoded URLs Images/links break across sites Use {{ frappe.utils.get_url() }} for absolute URLs

Accessing child table wrong Empty or error Use {% for item in doc.items %} not doc.child_table_name

Complex CSS in print format Styling lost in PDF Use inline styles, simple layouts, <table> for structure

Not handling None values 'None' string in output Use {{ value or '' }} or {% if value %}

Source Transparency

This detail page is rendered from real SKILL.md content. Trust labels are metadata-based hints, not a safety guarantee.

Related Skills

Related by shared tags or category signals.

Automation

frappe-router

No summary provided by upstream source.

Repository SourceNeeds Review
Automation

frappe-desk-customization

No summary provided by upstream source.

Repository SourceNeeds Review
Automation

frappe-ui-patterns

No summary provided by upstream source.

Repository SourceNeeds Review
Automation

frappe-reports

No summary provided by upstream source.

Repository SourceNeeds Review