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

发布于 2024-12-11 10:12:05 字数 1253 浏览 0 评论 0原文

我想在代码级别渲染大型非图形报表(数千页),从 .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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

月亮邮递员 2024-12-18 10:12:05

放置在 web.config 中的 标记内为我做的。 更多详情

Placing <trust legacyCasModel="true" level="Full"/> inside <system.web> tag in web.config did it for me. More details here

婴鹅 2024-12-18 10:12:05

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

returning datatable as datasource runs much faster than a list of objects

獨角戲 2024-12-18 10:12:05

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

  1. 将报告生成为最多 5-10 页的单独 PDF 文档(使用特定 PDF 库,例如免费 iTextSharpPDF 文件编写器
  2. 然后合并所有这些 PDF 文件 。

当您控制报告生成的进度时,此技术也很有用

Generating large PDF files requires memory but there is a trick to optimize the memory usage if you need to:

  1. generate the report as separate PDF documents with up to 5-10 pages (using specific PDF libraries like free iTextSharp or PDF File Writer
  2. then merge all these PDF files into one single large PDF document.

This technique is also useful as you control the progress of report generation.

空城旧梦 2024-12-18 10:12:05

删除SSRS报告中的所有表达式。
任何条件格式、着色和交替行,这都会大大减少您的下载时间。

Remove all the expressions in SSRS report.
Any conditional formatting , coloring and alternating rows , this should reduce your download time drastically.

鱼忆七猫命九 2024-12-18 10:12:05

经过我 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文