Books

Books

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

Print Templates

A print template sets how a document looks when you print it or save it as a PDF. A template is HTML with Jinja tags.

Open Print Templates

Click Setup > Print Templates in the sidebar. Click a template to open it in the Template Builder.

Frappe Books has standard templates for sales invoices, POS sales invoices, quotes, purchase invoices, payments, and shipments. You cannot edit or delete a standard template. To change one, duplicate it and edit the copy. Journal entries, purchase receipts, and stock movements have no standard template. To print them, create a template first.

A Books User can print with templates but cannot change them.

Create a Print Template

  1. Click Setup > Print Templates in the sidebar.
  2. Click New. The Template Builder opens with a sample template.
  3. Enter the Template Name in the page header. You cannot change it after you save.
  4. Below the preview, select the Template Type. The default is Sales Invoice.
  5. Edit the template in the editor on the right.
  6. Press Ctrl + Enter to update the preview.
  7. Click Save.

The preview shows the newest document of the template type. To preview a different document, select it in Display Doc.

You can also start a template from the print view of a document. Click the … button, and then click New template. The new template gets the type of the document.

Duplicate a Template

Open the template, and click … > Duplicate in the page header. A copy opens with CPY at the end of its name. Edit the copy and click Save. To delete a template, click … > Delete.

Edit a Template

The preview does not change while you type. To apply your changes, press Ctrl + Enter or click outside the editor. If the template has an error, the preview shows Template error and a message.

Template Builder with the Business - Sales Invoice template: the preview of invoice SINV-1039 (with Assam Tea, HSN/SAC 0902) on the left and the template code on the right.

Key Action
Ctrl + Enter Apply the changes to the preview.
Ctrl + S Save the template. In the editor, it applies your changes first. On macOS, press Cmd + S.
Ctrl + E Turn edit mode on or off. Edit mode makes the editor larger.
Ctrl + H Show or hide the Key Hints.

Except for Ctrl + S, use the Ctrl key also on macOS.

The … menu also has these actions:

  • Set print size: Select a Page Size, such as A5, Letter, or POS, or enter a height and width in cm. The default is A4. Then save the template.
  • Save template file: Download the template as a .template.html file.
  • Select template file: Replace the editor content with a file.

Write a Template

For the Jinja syntax, see the Jinja template documentation. To see complete examples, open the standard templates.

To show a value, put its key between double curly braces, such as {{ doc.name }}. There are three sets of keys:

  • doc: The values of the printed document, such as doc.name and doc.grand_total. The keys change with the template type.
  • print: The values of the Print settings. Set them first with {%- set print = get_print_settings() -%}.
  • totals: Totals that the document does not store. Set them first with {%- set totals = get_print_totals(doc) -%}.

To see the doc and print keys of the template type, click Key hints below the editor. Custom fields also show there. The editor suggests keys while you type inside {{ }}.

Key Hints shows a table, such as the items of an invoice, as doc.items[number]. Use a for loop to show each row:

{% for row in doc.items %}
  <p>{{ row.item | e }}: {{ books_format(row.amount, "Currency", doc.currency) }}</p>
{% endfor %}

books_format(value, fieldtype, currency) formats a value as Frappe Books shows it. Use "Currency", "Float", or "Date". Without a currency, it uses the company currency. A "Float" value uses the Float Precision of the Frappe System Settings and shows whole numbers without decimals.

Add | e to text that users enter, such as names and notes. Then HTML characters in the text show as text.

To show a value of a linked record, use frappe.db.get_value:

{{ frappe.db.get_value("Books Party", doc.party, "email") }}

Add CSS in a <style> element in the template, or use style attributes.

Key Value
print.logo, print.company_name Logo, Company Name
print.email, print.phone Email, Phone
print.address The full text of the Address
print.color, print.font Color, and the font of the Frappe Print Settings
print.display_logo Display Logo in Invoice
print.amount_in_words Display Amount In Words
print.display_time Display Time In Invoice
print.display_description Display Description In Invoice
print.displaytermsandconditions Display Terms and Conditions
print.terms_and_conditions Terms and Conditions
print.gstin, print.tax_id GSTIN or Tax ID from the General settings

The display settings do not change a template by themselves. Check them in your template, such as with {% if print.display_logo %}.

Totals Keys

Key Template Types Value
totals.sub_total All except Journal Entry The total without tax. For stock documents, the total amount.
totals.grand_total_in_words All except Journal Entry The grand total in words. For payments, the Amount in words.
totals.payment_details Sales Invoice, Purchase Invoice The submitted payments of the invoice. Each row has payment_method, amount (the part for this invoice), amount_paid, and outstanding_amount.
totals.amount_paid_in_words Payment The Amount Paid in words.
totals.taxes Payment The taxes of the paid invoices, with account and amount.

Set the Default Template

The print view opens with the default template of the document type. To set the defaults, use Print Templates in the Defaults tab of the Settings. For POS invoices, Frappe Books uses the POS Print Template of the POS profile, or else the one in the Defaults tab.

  1. Open a saved document.
  2. Click the printer icon in the page header. On a phone, tap Print at the bottom of the form.
  3. In Template Name, select a print template. On a phone, tap Template below the header.
  4. Click Save as PDF to download a PDF file, or click Print to open the print dialog of your browser.

Print view of a sales invoice with the company logo, address, and GSTIN, three items with their HSN/SAC codes (Assam Tea has 0902), the discount, CGST and SGST, and the grand total in words.

On a computer, you can also press Ctrl + P in the form, or Cmd + P on macOS. On a phone, you can tap Share to send the PDF to a different app, if your browser can share files.

You cannot print a cancelled document or a document with unsaved changes. The printer icon shows only when a template exists for the document type. Print opens a new browser tab. If Frappe Books shows Pop-up blocked, allow pop-ups for your site and try again.

  1. Click Setup > Settings in the sidebar.
  2. Click Print.
  3. In Logo, click Upload and select an image.
  4. Turn on Display Logo in Invoice.
  5. Click Save.

The Print settings also change the Color of the standard templates. The font of the Frappe Print Settings applies to all templates. See Settings.

Last updated 2 weeks ago
Was this helpful?
Thanks!