2

我们一直在对我们的 asp.net mvc3 网络应用程序上的一些慢速 PDF 报告进行计时,

有一个特别让我们大吃一惊……

SQL - 在几毫秒内返回 RDLC 处理 - 几百毫秒 PDF 生成 - 超过 4 分钟

我发现了这个:http ://social.msdn.microsoft.com/Forums/sqlserver/en-US/ca45fcc4-be69-410f-aaed-19b65f279330/reporting-services-sp1-slow-on-pdf-render

还有这个: 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 生成太糟糕了,我觉得我一定是做错了什么……

如果需要,这里的 PS 是更多的堆栈

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;
        }
4

0 回答 0