Template Filters

Note: Print Distributor has now been discontinued.

Templates let you insert some text into a property as the action is running. Using this you can make up a path based on several variables available to you.

Templates always start and end with the sequence ??. The first information in the template is the variable you want to insert and this is followed by any number of vertical bar characters and filters.

So a basic template for the users name might be:

The document ?? DocumentName ?? has been printed

This would then be converted to:

The document August Sales.xls has been printed

But what if you want to modify the variable before including it, for instance you may want to replace the spaces in the document name with underscore characters. To do this you add a filter after the variable name, in this case the replace filter:

The document ?? DocumentName  | replace " ", "_" ?? has been printed

This will give you the result:

The document August_Sales.xls has been printed

One of the most useful filters is dateformat, this will take a DateTime variable and format it for you:

Printed at ?? Now | dateformat @'yyyy\\MM\\dd' ??

The \\ in the format string is an escape; it inserts a \ character into the date format. yyyy gets converted to the year, MM to the month and dd to the day. The @ at the start of the string marks it as a verbatim string which removes the need for a layer of escaping.

Note: Variables have a type so there are some combinations that won’t make sense, for instance adding the dateformat filter to the SerialNumber variable will cause an error.

Filters

The available filters are:

Trim

Remove any leading and trailing whitespace characters.

Lower

Convert the string to lower case.

Upper

Convert the string to upper case.

String

Convert the variable to a string.

SubString

Extract a substring from some text, this takes two parameters, the start character (which is zero based) and an optional length. If you leave out the length then substring will return the rest of the text.

Truncate

Restrict text to a maximum length, so truncate 6 will shorten the variable to 6 characters.

Title

Changes text to title case, so “my FIRST File” becomes “My First File”.

Null

Do nothing

DateFormat

Format the date according to a format string. An example of this is:

Printed at ?? Now | dateformat @'yyyy\\MM\\dd' ??

The \\ in the format string is an escape; it inserts a \ character into the date format. yyyy gets converted to the year, MM to the month and dd to the day.

Search .net date format for the full range of format strings available (there are a lot!)

Modulo

Modulo applies the modulo or remainder operator to a numeric value such as a serial number. For instance the template

?? serialnumber | modulo 1000 ??

will constrain the result to the values 0 to 1000.

The result of a % b is the value produced by a - (a / b) * b. The sign of the non-zero remainder is the same as that of the left-hand operand.

Pad

Pad out text with a leading character, for instance ?? SerialNumber | pad 6 ?? would turn 123 into 000123. The optional second parameter is the character to use for padding, this defaults to ‘0’

Regex and Regexi

Search and replace using regular expressions:

?? DocumentName | regexi "^([a-z]*) ", "$1_" ??

Regexi is the case insensitive verion of Regex.

Replace

Replaces all occurrences of a string with a new string. Takes two string parameters, the first is the search string, the second is the replacement. For example to replace all spaces with underscores use:

The document ?? DocumentName  | replace " ", "_" ?? has been printed

FileName

Extract the filename from a path, given the document name C:\Files\expenses.xls

?? DocumentName | filename ??  

will output expenses.xls.

Note: Not all application software puts the path into the document name, sometimes there may not be a path.

FileNameWithoutExtension

Extract the file name from a path without an extension.

StripInvalidPathCharacters

Remove characters which would be illegal in a file path.

StripSlashes

Remove slash (‘/’ and ‘') characters.