Framework

Framework

Open in ChatGPT
Ask ChatGPT about this page
Open in Claude
Ask Claude about this page

HTML print formats

An HTML print format is written by hand in HTML and Jinja. Use it when the Print Format Editor cannot produce the layout you need. For most formats, the editor is quicker and easier to maintain.

Applies to Frappe v16 and later.

Before you begin

You need:

  • permission to create Print Formats;
  • working knowledge of HTML, CSS and Jinja templates.

Create an HTML format

  1. Open the Print Format list and click Add Print Format.
  2. Pick the DocType and enter a Name.
  3. Set Start with to HTML and click Create.
  4. Write the template in HTML and save.

For a format you want to ship with an app, turn on developer mode and tick Standard. The format is then saved as files in the app and tracked in git.

Write the template

The document is available as doc:

<h2>{{ doc.select_print_heading or _("Sales Invoice") }}</h2>
<p>{{ doc.customer_name }}</p>

<table class="table table-bordered">
	<tr><th>{{ _("Item") }}</th><th class="text-right">{{ _("Amount") }}</th></tr>
	{% for row in doc.items %}
	<tr>
		<td>{{ row.item_name }}</td>
		<td class="text-right">{{ row.get_formatted("amount", doc) }}</td>
	</tr>
	{% endfor %}
</table>
  • _("text") translates text into the print language.
  • doc.get_formatted("fieldname") formats a value the way the form shows it, with currency and date formats.
  • frappe.get_doc, frappe.db.get_value and other helpers are available. See the Jinja API.
  • Add styles in the format's Custom CSS field.

Script and query reports can have their own print format, written in JavaScript templating. See Print formats for reports.

PDF engine

HTML formats use the PDF Generator set in Print Settings. wkhtmltopdf cannot lay out modern CSS such as flexbox and is no longer maintained, so use chrome unless a format depends on wkhtmltopdf.

Last updated 2 days ago
Was this helpful?
Thanks!