2011-10-24 36 views
10

我想在代碼級別渲染大型的非圖形報告(數千頁),忽略了.rdlc文件中的僅僅阻塞瀏覽器的ReportViewer控件。當我測試呈現一個有2000頁的報告時,Microsoft.Reporting.WebForms.LocalReport.Render方法需要大約半小時才能完成,這被認爲是不好的用戶體驗。如何在代碼中從.rdlc導出PDF時提高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); 

任何幫助非常感謝,謝謝提前!

回答

0

返回數據表作爲數據源的運行速度要比對象

0

生成較大的PDF文件列表快得多需要的內存,但有一個小竅門,如果你需要優化內存使用:

  1. 生成報告與高達5-10頁(使用如免費iTextSharpPDF File Writer
  2. 特定的PDF庫,那麼所有這些PDF文件合併成一個單一的大PDF文件單獨的PDF文檔。

當您控制報告生成的進度時,此技術也很有用。