首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何为LocalReport设置` `EnableExternalImages = true`

如何为LocalReport设置` `EnableExternalImages = true`
EN

Stack Overflow用户
提问于 2021-04-15 20:34:45
回答 1查看 100关注 0票数 1

我正在使用reporting package - AspNetCore.Reporting -2.1.0。我想打印具有外部图像的RDLC报告。在渲染到pdf时发生错误。

代码语言:javascript
复制
An error occurred during local report processing.;Report 'Payslip' contains external images. The EnableExternalImages property has not been set for this report.

渲染我的部分代码:

代码语言:javascript
复制
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;
EN

回答 1

Stack Overflow用户

发布于 2021-04-21 12:33:09

在渲染之前运行此命令

代码语言:javascript
复制
localReport.EnableExternalImages = true;

编辑:

您正在使用的开源库似乎没有公开您需要的变量或方法。

但是这些方法在密封类的私有变量中。

但是,你仍然可以通过反射来改变它的值。

它不是很漂亮,但它会完成这项工作。

代码语言:javascript
复制
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);
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/67108571

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档