在代码中从 .rdlc 导出 PDF 时,如何提高 LocalReport.Render 方法的性能?
我想在代码级别渲染大型非图形报表(数千页),从 .rdlc 文件中省略只会堵塞浏览器的 ReportViewer
控件。当我测试渲染大约 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);
非常感谢任何帮助,提前致谢!
I want to render big non-graphical reports (thousands of pages) in the code level, omitting the ReportViewer
control that just jams the browser, from the .rdlc files. When I test to render a report that is somewhat 2000 pages, the Microsoft.Reporting.WebForms.LocalReport.Render
method takes approximately half an hour to finish, that is considered as bad user experience.
Are there any tricks or alternative solutions to improve the performance of the rendering: in code, re-designing the .rdlc file, or somewhere else, e.g, just increasing hardware?
Example code:
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);
Any help is much appreciated, thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
将
放置在web.config
中的
标记内为我做的。 更多详情Placing
<trust legacyCasModel="true" level="Full"/>
inside<system.web>
tag inweb.config
did it for me. More details here返回数据表作为数据源运行速度比对象列表快得多
returning datatable as datasource runs much faster than a list of objects
生成大型 PDF 文件需要内存,但如果需要,可以使用一个技巧来优化内存使用:
当您控制报告生成的进度时,此技术也很有用
Generating large PDF files requires memory but there is a trick to optimize the memory usage if you need to:
This technique is also useful as you control the progress of report generation.
删除SSRS报告中的所有表达式。
任何条件格式、着色和交替行,这都会大大减少您的下载时间。
Remove all the expressions in SSRS report.
Any conditional formatting , coloring and alternating rows , this should reduce your download time drastically.
经过我 5 个月的调查,没有办法以可接受的速度水平提高 RDLC 性能。 RDLC 是为收据和发票等简单报告创建的。如果没有任何内部表达式的报表页面数量超过 100 个,或者带有动态内部表达式的页面数量超过 50 个,则使用 html 是可接受的加载和呈现速度的最佳选择。
There is no way to improve the RDLC performance at acceptable speed level after my 5 months investigation. RDLC is created for SIMPLE report such as receipt and invoice. Using html is the best option for acceptable loading and rendering speed if the number of report pages is greater than 100 with no any internal expressions, or greater than 50 pages with dynamic internal expressions.