Overview
Outlines the steps to implement a dynamic watermark in a generated report, along with a sample data source and RML template attached for reference.
Steps to Add and Configure Dynamic Watermark in a Report
1. Create a New Section for the Watermark
a) Navigate to the Report tab panel. Right-click Sections and select Add Section.
b) Configure the new section as follows:
Untick all the page setup options except Show Section Header, and click finish.
Save the file to apply changes.
2. Bind Watermark Section and Add Function to Section 1
Navigate to the Report tab panel, right-click Section 1, and select Edit Section.
a) In the Watermark tab:
Bind the watermark section created earlier by selecting it under the Section field.
b) In the Script tab:
Paste the following function into the On Render Begin field:
init();
Click Finish once done.
Note: The init()
function ensures a copy of the rendering context for Section 1.
3. Add a Watermark Retrieval Script
a) Navigate to the Functions tab.
b) In the Function Definitions sub-tab. Paste the following script into the main field:
importClass(Packages.com.elixirtech.report2.logical.RenderStack);
var rsCxt = null;
function init() {
rsCxt = RenderStack.current().getContext();
}
function currentValue() {
var data = rsCxt.getData();
var nextIdx = data.getRecordIndex()+1;
if (nextIdx>=data.getRecordCount()) return "";
var record = data.getDataTable().getRecord(nextIdx);
var idx = record.getSchema().getColumnIndex("wmark");
return record.getData(idx);
}
Note: This script retrieves the “wmark” value dynamically from the next record in the dataset for conditional rendering or processing.
4. Add SVG Element Into the Watermark Section
a) Navigate to the Layout tab. Select the newly created watermark section and adjust its Section Header height in the position panel.
b) Select the SVG tool from the tools panel.
Click under the Section Header to add the SVG. In the SVG Wizard, paste the following script:
<?xml version="1.0" encoding="UTF-8"?>
<svg xmlns="http://www.w3.org/2000/svg" xmlns:rml="http://www.elixirtech.com/ElixirReport/RML" width="600" height="850" version="1.1" contentScriptType="text/ecmascript" contentStyleType="text/css">
<defs>
<pattern id="textstripe" patternUnits="userSpaceOnUse" width="120" height="90" patternTransform="rotate(-45)">
<text y="35" font-family="Arial" font-size="20" fill="lightgrey">${=currentValue();}</text>
</pattern>
</defs>
<rect width="100%" height="100%" fill="url(#textstripe)" />
</svg>
c) Ensure the SVG element is selected and set the following:
- Tick Dynamic under the right panel.
- Tick the Fill attribute under the Position section.
- Adjust the Image Resolution to improve clarity if the SVG appears blurry.
Note: The SVG script dynamically creates a repeating diagonal watermark pattern with text based on the currentValue()
function.
5. Log Watermark Information to the Section Header
a) Navigate to the Functions tab. Ensure the Section Header of the watermark section is selected in the right panel.
Paste the following script in the On Render Begin field:
Log.info("wmark");
Note: This script logs the “wmark” value for debugging or informational purposes.
Result
The watermark displays a repeating diagonal text pattern derived from the dataset.
Attachments
- Sample Data Source
- RML Template
Dynamic Watermark Sample.zip (3.5 KB)