简体   繁体   中英

How can I improve the performance of the LocalReport.Render method when exporting PDF from .rdlc in code?

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, eg, 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!

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

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

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.

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM