当在代码中从.rdlc导出PDF时,如何提高LocalReport.Render方法的性能?

10

我想在代码层面渲染非图形化的大型报告(数千页),避免使用会导致浏览器卡顿的ReportViewer控件,而是直接从.rdlc文件中进行渲染。当我尝试渲染一个约有2000页的报告时,Microsoft.Reporting.WebForms.LocalReport.Render方法需要大约半个小时才能完成,这被认为是糟糕的用户体验。

有没有什么技巧或替代方案可以提高渲染性能:例如在代码中重新设计.rdlc文件或其他地方,比如只增加硬件?

示例代码:

LocalReport localReport = new LocalReport();
localReport.ReportPath = Server.MapPath("~/report.rdlc");

SetDataSources(ref localReport);

string reportType = "PDF";
string mimeType;
string encoding;
string fileNameExtension;

string deviceInfo =
"<DeviceInfo>" +
"  <OutputFormat>PDF</OutputFormat>" +
"  <PageWidth>8.5in</PageWidth>" +
"  <PageHeight>11in</PageHeight>" +
"  <MarginTop>0in</MarginTop>" +
"  <MarginLeft>0in</MarginLeft>" +
"  <MarginRight>0in</MarginRight>" +
"  <MarginBottom>0in</MarginBottom>" +
"</DeviceInfo>";
}

Warning[] warnings;
string[] streams;
byte[] renderedBytes;

//Render the report
renderedBytes = localReport.Render(
            reportType,
            deviceInfo,
            out mimeType,
            out encoding,
            out fileNameExtension,
            out streams,
            out warnings);

非常感谢您的帮助,提前致谢!

5个回答

1
web.config文件的<system.web>标签中添加<trust legacyCasModel="true" level="Full"/>解决了我的问题。更多细节请参见此处

0

生成大型PDF文件需要内存,但如果需要优化内存使用,则有一个技巧:

  1. 使用特定的PDF库(如免费的iTextSharpPDF File Writer)将报告生成为最多5-10页的单独PDF文档
  2. 然后将所有这些PDF文件合并成一个单独的大型PDF文档。

这种技术还有一个好处,就是您可以控制报告生成的进度。


0

将DataTable作为数据源返回比对象列表运行速度快得多


0

在经过5个月的调查后,我发现没有办法提高RDLC性能以达到可接受的速度水平。 RDLC是为简单报告(如收据和发票)创建的。如果报告页面数量大于100且没有任何内部表达式,或者大于50页并带有动态内部表达式,则使用HTML是可接受的加载和渲染速度的最佳选择。


0
删除 SSRS 报表中的所有表达式。 任何条件格式,着色和交替行,这样可以大幅降低下载时间。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接