Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reportviewer print button in Google Chrome

for what I've read, reportviewer print button doesn't work in Google Chrome and Firefox because it's made with an ActiveX control which only works in IE. So I was trying to make an asp.net button outside the report and print the report programatically, but it's being a pain and I was wondering if there is a simpler workaround to get the report to print in Google Chrome.

Edit/Update: I've found this reportviewer print button which is supposed to work for Firefox and Google Chrome, it seems to be working for Firefox but it prints me a blank page in Google Chrome. http://cafalse.blogspot.com/2011/04/reportviewer-print-button-for-firefox.html

like image 446
Pablo Avatar asked Nov 14 '22 10:11

Pablo


1 Answers

If you don't mind adding your own button somewhere on the page. This only works if your way of generating the report looks similar to mine. Basically I take the Report, render it into bytes and send those bytes as a Response in pdf format. This will open up the file as PDF which most browser such as Chrome support. This requires the user to take the extra step and click print.

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();
like image 149
Athanasios Karagiannis Avatar answered Dec 11 '22 23:12

Athanasios Karagiannis