如何在Stimulsoft中动态添加水印到报告中

问题描述 投票:0回答:3

我想动态添加水印到 Stimulsoft 中生成的报告中。水印不能硬编码,只有在 TEST 环境中生成报告时才会出现。

我有一个变量来检查报告是否是在测试环境中创建的: isTestEnv

这意味着如果水印以老式方式添加到页面,我会使用:

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

但事实并非如此。我必须在生成报告时添加水印。有谁知道怎么做吗

所有页面上的文字都相同,只是写着“测试”。但如何将其纳入报告是个谜。

c# dynamic stimulsoft
3个回答
1
投票

您可以使用此代码并在报告中设置水印图像

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

0
投票

您可以在设计时将报告页面水印设置为某些报告变量,并在代码中设置报告变量的值。

类似这样的:

StiReport 报告 = new StiReport(); 报告.Load("REPORT_TEMPLATE_PATH");

//可以使用if条件检查该变量是否存在 report.Dictionary.Variables["WATERMARK_VARIABLE_NAME"] = "YOUR_TEXT";

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


0
投票

您可以使用此解决方案:

                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);
© www.soinside.com 2019 - 2024. All rights reserved.