asp.net-core - 如何为 LocalReport 设置`EnableExternalImages = true`
问题描述
我正在使用报告包 - AspNetCore.Reporting -2.1.0。我想打印具有外部图像的 RDLC 报告。在呈现为 pdf 期间发生错误。
An error occurred during local report processing.;Report 'Payslip' contains external images. The EnableExternalImages property has not been set for this report.
渲染我的部分代码:
string reportFileName = "Payslip.rdlc";
if (paySlip.IsHourlySalary)
reportFileName = "Payslip.rdlc";
else
{
reportFileName = "PaySlipForAnnual.rdlc";
}
string ReportPath;
if (_webHostEnvironment != null)
ReportPath = Path.Combine(_webHostEnvironment.ContentRootPath + "\\TMReports", reportFileName);
else
{
ReportPath = Path.Combine(Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location) + "/TMReports", reportFileName);
}
LocalReport localReport = new LocalReport(ReportPath);
message += " Before localReport.SetParameters(param);";
message += " Before localReport.DataSources.Add(cd);";
localReport.AddDataSource("dsPaySlip", dtPaySlip); // Add datasource here
message += " Before byte[] bytes = localReport.Render(";
var result = localReport.Execute(RenderType.Pdf, 1, reportParams, mimeType);
return result.MainStream;
解决方案
在渲染之前运行它
localReport.EnableExternalImages = true;
编辑:
似乎您正在使用的开源库没有公开变量或您需要的方法。
但是你仍然可以通过反射来改变它的价值......
它不漂亮,但它会完成工作。
AspNetCore.Reporting.LocalReport rpt = new AspNetCore.Reporting.LocalReport(yourReportPath);
BindingFlags bindFlags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static;
FieldInfo field = rpt.GetType().GetField("localReport", bindFlags);
object rptObj = field.GetValue(rpt);
Type type = rptObj.GetType();
PropertyInfo pi = type.GetProperty("EnableExternalImages");
pi.SetValue(rptObj, true, null);
推荐阅读
- python - 通过任何方法生成对抗样本时接收断言失败
- grails - 在 Grails 上响应错误时如何过滤 deniedValue 属性?
- python-3.x - Jupyterlab 选项卡完成没有提供有用的建议
- c - 使用 CTRL-D 退出带有 fgets 的 while 循环
- android - Android:AWS 上传的所选图像出现无效文件错误
- c - 如何创建 Makefile 来正确编译我的 C 代码?
- python-3.x - 在 Google colab 中使用海龟图形
- java - 如何使用下面的 Java 代码行转换我的 XML 数据?
- python - 在 JupyterNotebook 中安装 pip 时出现“熊猫构建轮子失败”
- php - 如何在 PHP guzzle 中验证异步请求?