Formatting within pdfMachine merge

pdfMachine merge supports full liquid templating language in HTML templates and the email body, and also has partial support for liquid (liquid filters only) in Microsoft Word/Excel/PowerPoint document templates.

Liquid allows you to apply formatting, perform loops, conditionals etc based on the values from your datasource. All the standard filters and tags are supported as mentioned here Liquid For Designers and here DotLiquid For Designers.

Note: To use Liquid Templating Tags in the email body the email body editor should always be in "Source" mode. The "wysiwig" mode will not preserve the Liquid Tags.

Using filters to format merge fields

Liquid contains filters which process the value of merge fields before output.
eg. {{ name | capitalize }} which capitalize words in the input sentence.
pdfMachine merge also has some custom filters (not part of Liquid specification) for dates, numbers and currency.

Examples of merge field formatting can be found here.

Specific examples :

Repeat tag

Works with HTML templates. Repeats the current table row, list item or div. This is a shortcut for the Liquid 'for' loop.
Specifically, the Liquid tag "{% for row in _rows %}" is placed in the parent tr, li or div tag.

This can be used when the "Rows to emails method" is set to "one or more rows generates an email", which has the effect of grouping the rows based on a merge field, usually the email address.

The Liquid for loop does not work well for visual html editors when used around table rows, so this is the preferred option.

Note in the example the merge field names must be prefixed with "row."

Name Amount
{%repeat%}{{}} {{row.amount}}
Name Amount
Dave 1230
Dave 1000

Looping and conditionals

Liquid also contains tags which support looping and conditionals
{% for desc in desc_array) %} html here {% endfor -%} which repeats the enclosed html for each of the elements of desc_array.  Note: Use forloop.index0 for the current index.
{% cycle 'rows':'LightGreyBackground', 'DarkGreyBackground' %} to alternate row colors in a table.

For an example of using the above in a template:
Click here to see an example HTML merge template using liquid.
Click here to see an example of the PDF generated.
When you install pdfMachine merge, a profile is setup with this demo invoice template, which you try out and customize to your requirements.

When using HTML templates, for best results you will need to set certain print options in Internet Explorer

  • Turn off Internet Explorer print headers and footers by File | Page Setup and change them all to "empty"
  • Turn on background colors for printing by File | Page Setup, tick "Print Background Colors and Images"

If you need help or more information on this feature please contact

$page $maxpage

These are special variables that are used with HTML templates. They are converted to the "current page" and the "maximum number of pages" in the PDF document. e.g. you might create a HTML stationery file with the text "$page of $maxpage".

Line items /Bundled data

Rows from the data source can become line items in the email or PDF.

Bundled data can be formatted using javascript or as liquid arrays.
If there is a column in the data source called description, it is available as {{description}}
Where there is bundled rows (multiple rows with the same email address) in the data source, the multiple rows are passed in as an array in a variable called description_array.  This is accessed as {{ description_array[0] }}, {{description_array[1] }} etc.

Review the example profile here to see how to set up a profile with line items.