--- title: Weasyprint Templates --- ## WeasyPrint Templates We use the powerful [WeasyPrint](https://weasyprint.org/) PDF generation engine to create custom reports and labels. !!! info "WeasyPrint" WeasyPrint is an extremely powerful and flexible reporting library. Refer to the [WeasyPrint docs](https://doc.courtbouillon.org/weasyprint/stable/) for further information. ### Stylesheets Templates are rendered using standard HTML / CSS - if you are familiar with web page layout, you're ready to go! ### Template Language Uploaded report template files are passed through the [django template rendering framework]({% include "django.html" %}/topics/templates/), and as such accept the same variable template strings as any other django template file. Different variables are passed to the report template (based on the context of the report) and can be used to customize the contents of the generated PDF. ### Context Variables !!! info "Context Variables" Templates will have different variables available to them depending on the report type. Read the detailed information on each available report type for further information. Please refer to the [Context variables](./context_variables.md) page. ### Conditional Rendering The django template system allows for conditional rendering, providing conditional flow statements such as: ``` {% raw %} {% if %} {% do_something %} {% elif %} {% else %} {% endif %} {% endraw %} ``` ``` {% raw %} {% for in %} Item: {{ item }} {% endfor %} {% endraw %} ``` !!! info "Conditionals" Refer to the [django template language documentation]({% include "django.html" %}/ref/templates/language/) for more information. ### Localization Issues Depending on your localization scheme, inputting raw numbers into the formatting section template can cause some unintended issues. Consider the block below which specifies the page size for a rendered template: ```html {% raw %} {% endraw %} ``` If localization settings on the InvenTree server use a comma (`,`) character as a decimal separator, this may produce an output like: ```html {% raw %} {% endraw %} ``` The resulting `{% raw %} {% endraw %} ``` !!! tip "Close it out" Don't forget to end with a `{% raw %}{% endlocalize %}{% endraw %}` tag! !!! tip "l10n" You will need to add `{% raw %}{% load l10n %}{% endraw %}` to the top of your template file to use the `{% raw %}{% localize %}{% endraw %}` tag.