Filgard
Filgard

Reputation: 37

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.

Upvotes: 0

Views: 1610

Answers (3)

ahmad salimi
ahmad salimi

Reputation: 11

you can use this solution :

                var rpt = new StiReport();
                rpt.Load(Server.MapPath(@"Report.mrt"));
                rpt.Dictionary.Databases.Clear();
                rpt.Dictionary.DataSources.Clear();
                rpt.Dictionary.Variables.Add("your_variable", variable_value );
                rpt.Pages[0].Watermark.Angle = 45;
                rpt.Pages[0].Watermark.Text = "Your Text"

                rpt.Dictionary.Synchronize();
                rpt.Dictionary.RegRelations();
                rpt.Dictionary.Synchronize();
                StiReportResponse.ResponseAsPdf(this, rpt, false);

Upvotes: 0

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");
});

Upvotes: 1

Amit Ranjan
Amit Ranjan

Reputation: 1

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();

Upvotes: 0

Related Questions