'How to dynamically add watermark to report in Stimulsoft

I would like to dynamically add watermark to a report that is generated in Stimulsoft. The watermark can not be hard-coded and only appear if the report was generated in TEST environment.

I have a variable that checks if the report was created in test environment: isTestEnv

Which means that if the watermark was added to the page the old fashioned way I would use:

if(isTestEnv == true) {
   Page1.Watermark.Enabled = true;
} else {
   Page1.Watermark.Enabled = false;
}

But this is not the case. I have to add the watermark when generating the report. Does anyone know how to?

The text is same on all pages it simply says "TEST". But how to push that into a report is the mystery.



Solution 1:[1]

you can use this code and set your water mark image in your report

Stimulsoft.Base.StiLicense.loadFromFile("../license.key");
var options = new Stimulsoft.Viewer.StiViewerOptions({showTooltips:false});
var viewer = new Stimulsoft.Viewer.StiViewer(options, "StiViewer", false);
var report = new Stimulsoft.Report.StiReport({isAsyncMode: true});

report.loadFile("Backgroundimg.mrt");
var page = report.pages.getByIndex(0);

page.watermark.image = Stimulsoft.System.Drawing.Image.fromFile('test.jpg');
page.watermark.aspectRatio = true;
page.watermark.imageStretch = true;
page.watermark.imageShowBehind= true;

report.renderAsync(function () {
    viewer.report = report;
    viewer.renderHtml("viewerContent");
});

Solution 2:[2]

You can set the report page watermark to some Report variable at design time and in your code set the value for the report variable.

Something like this:

StiReport report = new StiReport(); report.Load("REPORT_TEMPLATE_PATH");

//You can check if this variable exists or not using an if condition report.Dictionary.Variables["WATERMARK_VARIABLE_NAME"] = "YOUR_TEXT";

report.Show();//or report.ShowWithWpf();

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 mohammad reza pourghorban
Solution 2 Amit Ranjan