Google Chrome中的Reportviewer打印按钮

时间:2012-02-14 11:56:39

标签: asp.net google-chrome reportviewer

对于我所阅读的内容,reportviewer打印按钮在Google Chrome和Firefox中不起作用,因为它是使用仅在IE中运行的ActiveX控件制作的。因此,我试图在报告之外制作一个asp.net按钮并以编程方式打印报告,但这很痛苦,我想知道是否有更简单的解决方法可以在Google Chrome中打印报告。

编辑/更新:我发现这个报告查看器打印按钮应该适用于Firefox和谷歌浏览器,它似乎适用于Firefox,但它在Google Chrome中打印了一个空白页面。 http://cafalse.blogspot.com/2011/04/reportviewer-print-button-for-firefox.html

1 个答案:

答案 0 :(得分:1)

如果您不介意在页面的某处添加自己的按钮。这仅在您生成报告的方式与我的相似时才有效。基本上我采用报告,将其呈现为字节并将这些字节作为PDF格式的响应发送。这将打开PDF格式的文件,Chrome支持大多数浏览器。这要求用户采取额外步骤并单击打印。

ServerReport sr = new ServerReport();
ReportViewer.ProcessingMode = ProcessingMode.Remote;
sr = ReportViewer.ServerReport;
sr.ReportServerUrl = new Uri("http://****/****");
sr.ReportPath = "/Report";
ReportParameter paramDateFrom = new ReportParameter();
ReportParameter paramDateTo = new ReportParameter();
ReportParameter paramState = new ReportParameter();
ReportParameter paramCounty = new ReportParameter();
string dateFrom = TB_Date_From.Text;
string dateTo = TB_Date_To.Text;
string state = DDL_State.SelectedValue;
string county = DDL_County.SelectedValue;
paramDateFrom.Name = "DateFrom";
paramDateFrom.Values.Add((dateFrom != "" ? dateFrom : null));
paramDateTo.Name = "DateTo";
paramDateTo.Values.Add((dateTo != "" ? dateTo : null));
paramState.Name = "State";
paramState.Values.Add((state != "" ? Common_Functions.resolveStateID(state) : null));
paramCounty.Name = "County";
paramCounty.Values.Add((county != "" ? Common_Functions.resolveCountyID(county) : null));
ReportViewer.ServerReport.SetParameters(new ReportParameter[] { paramDateFrom, paramDateTo, paramState, paramCounty });
// DUMP PDF TO BROWSER
Warning[] warnings;
string[] streamids;
string mimeType, encoding, extension;
byte[] bytes = ReportViewer.ServerReport.Render("PDF", null, out mimeType, out encoding, out extension, out streamids, out warnings);
Response.Buffer = true;
Response.Clear();
Response.ContentType = mimeType;
Response.AddHeader("content-disposition", "inline; filename=myfile." + extension);
Response.BinaryWrite(bytes);
string pdfPath = Server.MapPath("~") + "pdf." + extension;
FileStream pdfFile = new FileStream(pdfPath, FileMode.Create);
pdfFile.Write(bytes, 0, bytes.Length);
pdfFile.Close();
Response.Flush();
Response.End();