Watermark

Watermark

This section shows how to add a dynamic text as a watermark. The output looks like below:

An export of this template is included as an attachment.

The implementation is done in 3 steps:

1. Define a variable with the text
The first step is to define a variable with the text, that we want to convert into an image.

In this example we define a variable called, textForWatermark:

In this example we use the fixed text 'Hello world', but this can of course be set to a dynamic value.
2. Define a variable for the SVG image
Next we need to define a variable for the SVG image. 

In this case the image variable is defined like below:

The XPath expression is included below as text:
concat('<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 800 800" width="800" height="800"><text x="400" y="400" text-anchor="middle" dominant-baseline="middle" font-size="110" font-family="sans-serif" fill="#000" fill-opacity="0.12" stroke="#000" stroke-opacity="0.12" stroke-width="0" transform="rotate(45 400 200)">',$textForWatermark,'</text></svg>')

The image variable is here defined as svgImage and as you can see above the image variable refers to the variable, $textForWatermark, which contains the text, that we want to rotate and make into the watermark.

Just before the reference to the $textForWatermark variable you can see this: rotate(45 400 200). This specifies, that the text should be rotated 45 degrees. If you prefer another rotation, then you can simply change the number 45.
3. Insert the watermark image
The last element is the actual image. It is defined like below:


You cannot see the watermark directly in the result view, so you need to do e.g. a PDF preview to see it.

The image is defined via a URL, that use this XPath expression:
concat('base64://',ng:base64($svgImage),'.svg')

This expression converts the SVG image into base64 (with the function, ng:base64()) and then it tells InterformNG2, that the image is defined as a base64 data string (the initial base64 text).
 

    • Related Articles

    • Page header

      If you are creating a normal business document e.g. an invoice, then you probably want a fixed header with customer name and address and column headings for the detail lines. Such elements must be inserted in the page header element. To create a page ...
    • Page footer

      If you want to keep the same footer for all pages of a merge, then you should normally insert them in a footer element of the page element. To create a page footer element you need to right-click on the page element in the element tree and here ...