ActiveReports报表无法PDF打印的解决办法
操作方法
- 01
检查是否调用LoadDocument方法将报表加载到Silverlight报表查看器,由于使用LoadDocument加载的报表不带文件路径,让Silverlight报表查看器不知道报表在服务器端的具体位置,导致了PDF打印无法完成。有一个变通的方法解决此问题,如下步骤:
- 02
为运行报表和生成ID添加一个Service
- 03
使用以下代码添加ReportCache和IHttpHandler接口(Report.ashx)。这个主要用来缓存报表和获取rdf和准备打印的pdf的。
- 04
publicclassReport : IHttpHandler { publicvoidProcessRequest(HttpContext context) { stringid = context.Request.Params["id"]; if(string.IsNullOrEmpty(id)) { ThrowException(context.Response); return; } SectionDocument sd = ReportCache.GetSectionDocument(id); if(sd ==null) { ThrowException(context.Response); return; } stringtype = context.Request.Params["type"]; if(string.IsNullOrEmpty(type)) { type ="rdf"; } type = type.ToLower(); switch(type) { case"pdf": PdfExport pdfExport =newPdfExport(); stringprint = context.Request.Params["print"]; if(print ==null) { print ="false"; } print = print.ToLower(); if(print !="false") { pdfExport.Options.OnlyForPrint =true; } using(var outStream =newMemoryStream()) { // Put output into the stream pdfExport.Export(sd, outStream); // send the bits context.Response.Clear(); context.Response.ContentType ="application/pdf"; context.Response.AddHeader("content-disposition","inline; filename=ActiveReports.PDF"); context.Response.BinaryWrite(outStream.ToArray()); } break; case"rdf": default: using(MemoryStream outStream =newMemoryStream()) { // Put output into the stream sd.Save(outStream); // send the bits context.Response.Clear(); context.Response.BinaryWrite(outStream.ToArray()); } break; } } privatevoidThrowException(HttpResponse response) { response.ContentType ="text/html"; response.Write("The specified report was not found on the server"); response.Flush(); } publicboolIsReusable { get { returnfalse; } } }
- 05
自定义Silverlight报表查看器
- 06
使用DefaultSLViewerTemplates.xaml
- 07
自定义“打印”按钮
- 08
为绑定“打印”按钮命令