Asp.net mvc Rdlc到PDF渲染速度慢
我们在asp.net mvc3 web应用程序上对一些慢速PDF报告进行计时 有一件事让我们大吃一惊 SQL-在几毫秒内返回 RDLC处理—几百毫秒 PDF生成-超过4分钟 我发现: 这是: 解释如何通过优化RDLC来解决这个问题,但我想确保我在c代码中没有做任何愚蠢的事情 这是一个以RDLC作为PDF格式呈现的部分,它看起来很简单,但我是否以最佳方式进行了处理?我是否遵循最佳实践Asp.net mvc Rdlc到PDF渲染速度慢,asp.net-mvc,c#-4.0,pdf-generation,rdlc,Asp.net Mvc,C# 4.0,Pdf Generation,Rdlc,我们在asp.net mvc3 web应用程序上对一些慢速PDF报告进行计时 有一件事让我们大吃一惊 SQL-在几毫秒内返回 RDLC处理—几百毫秒 PDF生成-超过4分钟 我发现: 这是: 解释如何通过优化RDLC来解决这个问题,但我想确保我在c代码中没有做任何愚蠢的事情 这是一个以RDLC作为PDF格式呈现的部分,它看起来很简单,但我是否以最佳方式进行了处理?我是否遵循最佳实践 // build the byte stream answerBytes = localView
// 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生成太糟糕了,我觉得我一定是出了什么问题
另外,如果需要,这里有更多的堆栈
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;
}
public byte[]ByteStreamPdf(参考ByteStreamReportArgsCV args)
{
//应根据报告类型更改DeviceInfo设置
//http://msdn2.microsoft.com/en-us/library/ms155397.aspx
字符串deviceInfo=“”;
deviceInfo+=“PDF”;
if(参数景观)
{
deviceInfo+=“11英寸8.5英寸”;
}
其他的
{
deviceInfo+=“8.5in11in”;
}
deviceInfo+=“0.5inIn”;
deviceInfo+=“1英寸0.5英寸”;
deviceInfo+=“”;
deviceInfo=“”;
args.deviceInfo=deviceInfo;
args.ReportType=“Pdf”;
返回ByTestStreamReport(参考参数);
}
公共字节[]ByteStreamReport(参考ByteStreamReportArgsCV args)
{
警告[]警告;
字符串[]流线;
字符串编码;
字符串FNAMEXT;
字符串模拟类型;
字节[]应答字节;
LocalReport localViewer=新建LocalReport();
//启用外部映像…CR#20338 JK
localViewer.EnableExternalImages=true;
//构建报表数据源
//在记事本中打开.rdlc,在xml中查找部分
//使用下一行中的内容。
ReportDataSource rds=新的ReportDataSource(args.NameOfDatasetInRdlc,args.DataToFillReport);
//设置报告路径和数据源
IWebAccess webAccessHdl=ObjectFactory.GetInstance();
//下一行是HttpContext.Current.Request.MapPath(args.RdlcPathAndFname);更改为使用webaccess-EWB
localViewer.ReportPath=webAccessHdl.GetMapPath(args.RdlcPathAndFname);
localViewer.DataSources.Add(rds);
//添加rdlc需要的参数
如果(args.RptParameters!=null)
localViewer.SetParameters(args.RptParameters);
//子报告任务
如果(args.SubReportDataToFillReport!=null)
{
对于(int i=0;i0)
localViewer.SubreportProcessing+=
LoadSubreportProcessingEventHandler;
}
//子报表任务结束
//构建字节流
answerBytes=localViewer.Render(
args.ReportType、args.DeviceInfo XML、out mimeType、out encoding、out fnameExt、,
输出流线,输出警告);
//将VAR发送回客户机。
args.MineType=mimeType;
args.FnameExt=FnameExt;
//完成后处理本地查看器
Dispose();
返回应答字节;
}
嗨,埃里克-我看到了完全相同的问题。你能找到解决方案吗?我不记得是否是这个具体问题,但我们减少了在RDLC中传递和处理的字段数量,结果证明用c#做所有预处理的事情要快得多,然后将预处理的数据传递到RDLC。在rdlc中执行可能的绝对最小值(如分组)。RLDC中所有奇特的数据转换都非常缓慢。关于它的最终源代码?您使用CLR 4.0 AppPool和ASP.NET 4.5?这不是源代码更改,我们只是更改了报告和传入的对象。。我们所做的不是在报告的各个字段中进行计算,而是传递每个字段的最终答案。这需要在模型上有更多的字段,但在其他方面,代码方面没有什么大不了的。