如何为LocalReport设置`EnableExternalImages=true` [英] How to set `EnableExternalImages = true` for LocalReport

查看:13
本文介绍了如何为LocalReport设置`EnableExternalImages=true`的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是Report Package-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);

这篇关于如何为LocalReport设置`EnableExternalImages=true`的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆