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

C# 在代码中从.rdlc导出PDF时,如何提高LocalReport.Render方法的性能?,c#,pdf,rendering,reportviewer,localreport,C#,Pdf,Rendering,Reportviewer,Localreport,我希望在代码级别呈现大型非图形化报告(数千页),从.rdlc文件中省略阻塞浏览器的ReportViewer控件。当我测试渲染大约2000页的报告时,Microsoft.Reporting.WebForms.LocalReport.render方法大约需要半小时才能完成,这被认为是糟糕的用户体验 是否有任何技巧或替代解决方案可以提高渲染性能:在代码中,重新设计.rdlc文件,或者在其他地方,例如增加硬件 示例代码: LocalReport localReport = new LocalReport

我希望在代码级别呈现大型非图形化报告(数千页),从.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);
LocalReport LocalReport=newlocalreport();
localReport.ReportPath=Server.MapPath(“~/report.rdlc”);
SetDataSources(参考localReport);
string reportType=“PDF”;
字符串模拟类型;
字符串编码;
字符串文件名扩展名;
字符串设备信息=
"" +
“PDF”+
“8.5英寸”+
“11英寸”+
“0英寸”+
“0英寸”+
“0英寸”+
“0英寸”+
"";
}
警告[]警告;
字符串[]流;
字节[]渲染字节;
//提交报告
renderedBytes=localReport.Render(
报告类型,
deviceInfo,
输出mimeType,
输出编码,
输出文件名扩展名,
流出的溪流,
发出警告);

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

将datatable作为数据源返回要比对象列表运行得快得多

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

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

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

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

    放入
    标签中
    web.config
    为我做了这件事。

    经过5个月的调查,没有办法以可接受的速度水平提高RDLC的性能。RDLC是为简单的report,如收据和发票。如果报告页数大于100且没有任何内部表达式,或大于50页且具有动态内部表达式,则使用html是可接受的加载和呈现速度的最佳选择