4.6. Creating templates like a professional (Plain Text and XML)

The one thing that all template file formats supported by Fanurio have in common is that they all are text-based formats. Technically, Fanurio can handle any text-based format through its Freemarker "template engine".

Fanurio handles two types of text formats:

  • standard: HTML, Microsoft Word 2007, OpenDocument Text and OpenDocument Spreadsheet.

  • generic: plain text and XML.

All standard formats are explained in previous sections. This section is about the generic formats.

When scanning for templates, Fanurio will also include .txt and .xml files on the list. You can create a text-based template and save it as .txt or .xml and place it in the templates folder. Templates saved as .xml files are also checked to make sure they are valid XML files.

A generic text template can be used to implement any text-based format. For instance, you could use it to generate RTF (Rich Text Format) documents if you know the RTF syntax. The following section shows how to use a plain text file to create a Scribus template.

4.6.1. Example: Quicken

Quicken is a personal finance management tool developed by Intuit, Inc. Quicken can read and write data to QIF (Quicken Interchange Format) files. QIF files have the .qif extension and are plain text files.

This section shows what you need to do to export Fanurio invoices as QIF files. Before creating a QIF template, make sure you read the section that explains the template language.

!Type:Invoice
D${invoice.date?string("M/dd''yy")}
U${invoice.grandTotal.amount}
T${invoice.grandTotal.amount}
N${invoice.number}
P${client.name}
M${invoice.notes}
LBusiness Income/AA
A${client.attention}
A${client.address}
"A${client.city}, ${client.state} ${client.zip}"
A
A
[#foreach item in invoice.items]
SBusiness Income
"${item.description}"
${item.total}
[/#foreach]
XI1
XE${invoice.dueDate?string("M/dd''yy")}
XR0.0
XT0.00
[#foreach item in invoice.items]
XN${item.name}
X#${item.quantity}
X${item.price}
"XS${item.description}"
[/#foreach]
^

The best way to create a template in the QIF format is to create an invoice in Quicken and then export it to QIF. Once you do that, start replacing its fields with placeholders recognized by Fanurio.

The QIF template file is in the file quicken-invoice.qif.

4.6.2. Example: Scribus (DTP)

Scribus is an open source, multi-platform desktop publishing application that competes with Adobe InDesign and Quark XPress. It uses an XML-based file format for its files. Scribus files have the .sla extension.

This section shows what you need to do to export Fanurio invoices as Scribus files. Before creating a Scribus template, make sure you read the section that explains the template language.

Step 1: Create a sample invoice in Scribus

Start by creating a sample invoice that includes your business details, the contact information of your client, the invoice details and a table for the items that you need to invoice. Instead of entering actual data, you can use placeholders to specify things like your address or the invoice number.

For a list of all placeholders that you can use in a template, please see the reference section. Instead of creating a Scribus file from scratch, you can use this one.

Step 2: Transform the Scribus file into a template

There are a few things you need to do to transform a Scribus file into a template.

  1. File extension: Although the Scribus file uses an XML-based format, it needs to be saved as a plain text file and not as an XML file. A Scribus file is not XML-valid. The first thing you need to do is change the file extension from .sla to .txt.

  2. Repeated rows: The row that displays the details of an invoice item has to be repeated for each item. That's why all PAGEOBJECT elements must be wrapped by a list directive. Open the text template, find these elements and then surround them as shown below.

    [#list invoice.items as item]
        <PAGEBOBJECT ... />
        ...
        <PAGEBOBJECT ... />
    [/#list]
    
  3. Y coordinates: Page objects have absolute coordinates. When repeating elements that are used to represent rows, their YPOS attribute must be different for each row. PAGEBOBJECT elements now look like this:

    [#list invoice.items as item]
        <PAGEBOBJECT ... YPOS="${270 + 30 * (item_index + 1)}" ... />
        ...
        <PAGEBOBJECT ... />
    [/#list]
    

    where 270 is the Y coordinate for the header row and 30 is the height of the item row.

    Rows below the items rows also have to have a calculated Y coordinate because their position may vary with the number of items of an invoice.

    [#list invoice.items as item]
        <PAGEBOBJECT ... YPOS="${270 + 30 * (item_index + 1)}" ... />
        ...
        <PAGEBOBJECT ... />
    [/#list]
    
    <PAGEBOBJECT ... YPOS="${270 + 30 * invoice.items?size + 1}" ... />
    

Once you have the template ready, install it and then export an invoice. Make sure you change the extension manually to .sla because it is set by default to .txt.

The text template file based on the Scribus file is in the file scribus-invoice.txt.