我们一直在我们的asp.net mvc3网络应用程序上对我们的一些慢速PDF报告进行计时,
尤其有点让我们大吃一惊......
SQL - 在几百毫秒内返回 RDLC处理 - 几百毫秒 PDF生成 - 超过4分钟
并且: msdn page 2
通过优化RDLC来解释如何解决它,但我想确保我的c#代码中没有做任何愚蠢的事情。
以下是采用RDLC并将其呈现为PDF的部分,它看起来非常简单,但我是以最佳方式进行的吗?我是否遵循最佳做法?
// build the byte stream
answerBytes = localViewer.Render(
args.ReportType, args.DeviceInfoXML, out mimeType, out encoding, out fnameExt,
out streamids, out warnings );
// send out vars back to client.
args.MineType = mimeType;
args.FnameExt = fnameExt;
// dispose of local viewer when complete
localViewer.Dispose();
netLogHdl.Trace( "Done PDF work " );
return answerBytes;
PDF生成太糟糕我觉得我必须有一些错误...
P.S。如果需要,这里有更多的堆栈
public byte[] ByteStreamPdf(ref ByteStreamReportArgsCV args)
{
//The DeviceInfo settings should be changed based on the reportType
//http://msdn2.microsoft.com/en-us/library/ms155397.aspx
string deviceInfo = "<DeviceInfo>";
deviceInfo += "<OutputFormat>PDF</OutputFormat>";
if (args.Landscape)
{
deviceInfo += "<PageWidth>11in</PageWidth><PageHeight>8.5in</PageHeight>";
}
else
{
deviceInfo += "<PageWidth>8.5in</PageWidth><PageHeight>11in</PageHeight>";
}
deviceInfo += "<MarginTop>0.5in</MarginTop><MarginLeft>1in</MarginLeft>";
deviceInfo += "<MarginRight>1in</MarginRight><MarginBottom>0.5in</MarginBottom>";
deviceInfo += "</DeviceInfo>";
deviceInfo = "";
args.DeviceInfoXML = deviceInfo;
args.ReportType = "Pdf";
return ByteStreamReport(ref args);
}
public byte[] ByteStreamReport(ref ByteStreamReportArgsCV args)
{
Warning[] warnings;
string[] streamids;
string encoding;
string fnameExt;
string mimeType;
byte[] answerBytes;
LocalReport localViewer = new LocalReport();
// enable external images... CR # 20338 JK
localViewer.EnableExternalImages = true;
// build the Report Data Source
// open up your .rdlc in notepad look for <datasets> section in xml
// use what you find on the next line.
ReportDataSource rds = new ReportDataSource(args.NameOfDatasetInRdlc, args.DataToFillReport);
// set the report path and datasource
IWebAccess webAccessHdl = ObjectFactory.GetInstance<IWebAccess>();
//next line was HttpContext.Current.Request.MapPath(args.RdlcPathAndFname); changed to use webaccess - EWB
localViewer.ReportPath = webAccessHdl.GetMapPath(args.RdlcPathAndFname);
localViewer.DataSources.Add(rds);
// add parameters that rdlc needs
if (args.RptParameters != null)
localViewer.SetParameters(args.RptParameters);
//Sub Report Task
if (args.SubReportDataToFillReport != null)
{
for (int i = 0; i < args.SubReportDataToFillReport.Length; i++)
{
ReportDataSource subRds = new ReportDataSource(args.SubReportNameOfDatasetInRdlc[i],
args.SubReportDataToFillReport[i]);
localViewer.DataSources.Add(subRds);
}
if (args.SubReportDataToFillReport.Length > 0)
localViewer.SubreportProcessing +=
LoadSubreportProcessingEventHandler;
}
//End of Sub Report Task
// build the byte stream
answerBytes = localViewer.Render(
args.ReportType, args.DeviceInfoXML, out mimeType, out encoding, out fnameExt,
out streamids, out warnings);
// send out vars back to client.
args.MineType = mimeType;
args.FnameExt = fnameExt;
// dispose of local viewer when complete
localViewer.Dispose();
return answerBytes;
}