How to print RDLC Report in Firefox - c#

I want to print my RDLC report in Firefox but the Print button icon is not displaying in Firefox browser but It works fine in IE.
Can anyone guide me how to print my report in Firefox browser.

Unfortunately there is no way to print an rdlc report in firefox.
Rdlc print is only works in ie, due to the activeX requirements.
More info here:Configuring and Using the ReportViewer Toolbar
There is an article on msdn about how print a local report without preview, but its only works with winforms report viewer. In asp.net you cannot acces to the client's printer.
Walkthrough: Printing a Local Report without Preview
Instead of print in firefox, you can export rdlc directly.
For an example:
Warning[] warnings;
string[] streamIds;
string mimeType = string.Empty;
string encoding = string.Empty;
string extension = string.Empty;
string filename = "YourFileName";
// Setup the report viewer object and get the array of bytes
ReportViewer viewer = new ReportViewer();
viewer.ProcessingMode = ProcessingMode.Local;
viewer.LocalReport.ReportPath = "YourReportHere.rdlc";
byte[] bytes = viewer.LocalReport.Render("PDF", null, out mimeType, out encoding, out extension, out streamIds, out warnings);
// Now that you have all the bytes representing the PDF report, buffer it and send it to the client.
Response.Buffer = true;
Response.Clear();
Response.ContentType = mimeType;
Response.AddHeader("content-disposition", "attachment; filename=" + fileName + "." + extension);
Response.BinaryWrite(bytes); // create the file
Response.Flush(); // send it to the client to download

Related

Print aspx page to PDF on button click, but print PDF serverside

I have a report that's displayed on a webpage, and the users have been printing this webpage to PDF. What I need is for the webpage to automatically print to PDF (save) to a location on the websites server when user clicks a button.
iTextSharp doesn't seem to let me just save the PDF exactly how it looks when you Print To PDF (keeping css etc), also there's some licencing complications. PrinceXML looks good but is way too expensive.
Is there no way to open a new aspx page and then print it to PDF server side?
You can use the built-in RLDC report. It's free, has a nice design and features, and allows you to print to PDF. You don't need to save a PDF file and worry about managing and deleting it, simply print it to a stream and use the stream to download.
Something like this:
Warning[] warnings;
string[] streamids;
string mimeType;
string encoding;
string extension;
byte[] bytes = reportViewer.LocalReport.Render("PDF", null, out mimeType, out encoding,
out extension, out streamids, out warnings);
And then write bytes to the download stream.
Response.Buffer = true;
Response.Clear();
Response.ContentType = mimeType;
Response.AddHeader("content-disposition", "attachment; filename= filename" + "." + extension);
Response.OutputStream.Write(bytes, 0, bytes.Length);
Response.Flush();
Response.End();

When downloading the image in ipad mini, it opens in encoded format

I have the below code to download the file
byte[] byteInfo = System.IO.File.ReadAllBytes(Path.Combine(System.Web.HttpContext.Current.Server.MapPath(args.Path), args.Names[0]));
Response.Clear();
Response.BufferOutput = true;
Response.ContentType = MimeMapping.GetMimeMapping(Path.Combine(args.Path, args.Names[0]));
Response.AddHeader("Content-Disposition", "attachment; filename= " + args.Names[0]);
Response.BinaryWrite(byteInfo);
It works well on Windows and MAC devices. But on IPAD mini, it open the image in encoded format like below
IHDR o³oa sRGB ®Îé ïiTXtXML:com.adobe.xmp <x:xm
How to resolve it?
I have resolve this issue by adding
Response.Flush()
Response.End()

Render SSRS report in PDF format in ASP.NET

I have some deployed SSRS reports on the server. Now I am accessing those reports from my ASP.NET application. After some research I found that default print button of the ReportViewer will not be visible in Chrome or any web browser except Internet Explorer. So all I want to render the Reports in PDF format so user can take the print out of PDF format without saving the file. Here's the piece of code I am using:
IReportServerCredentials irsc = DBConnection.NetworkCredentials();
ReportViewer1.ServerReport.ReportServerCredentials = irsc;
List<ReportParameter> list = new List<ReportParameter>();
list.Add(new ReportParameter("ref_no", refNo));
ReportViewer1.ServerReport.SetParameters(list);
ReportViewer1.ServerReport.Render("PDF");
ReportViewer1.ServerReport.Refresh();
But its not working. The reports are getting rendered but not in PDF format. And if someone take the print out, alignment of all the fields like Tablix, TextBox are not properly aligned. Does any one know how can I do this?
Fortunately, after so many try, have found the solution. This is what I have done:
IReportServerCredentials irsc = DBConnection.NetworkCredentials();
ReportViewer1.ServerReport.ReportServerCredentials = irsc;
List<ReportParameter> list = new List<ReportParameter>();
list.Add(new ReportParameter("ref_no", refNo));
ReportViewer1.ServerReport.SetParameters(list);
byte[] data = ReportViewer1.ServerReport.Render("pdf");
Response.Clear();
Response.ContentType = "application/pdf";
Response.AddHeader("Content-Disposition", "inline;filename=Manifest_Print.pdf");
Response.BinaryWrite(data);
And it worked for me.

Opening generated PDF after saving it in browser

I had a method to populate PDF in browsers. It can have PDF be shown in the browsers perfectly. However after I clicked "SAVE" bottom, and open the downloaded file from my local, it shows
"Adobe Reader could not open 'xxx.pdf' because it is either not a supported file type or because the file has been damaged (for example, it was sent as an email attachment and wasn't correctly decoded)."
Below is my code
public static void PopulatePDF(byte[] PDFcontents)
{
var response = HttpContext.Current.Response;
response.AppendHeader("Content-Disposition", "inline; filename=xxx.pdf");
response.AppendHeader("Content-Length", PDFcontents.Length.ToString());
response.AppendHeader("Content-Transfer-Encoding", "binary");
response.OutputStream.Write(PDFcontents,0,contents.PDFcontents);
response.BufferOutput = true;
response.Buffer = true;
response.ContentType = System.Net.Mime.MediaTypeNames.Application.Pdf;
response.BinaryWrite(PDFcontents);
response.Flush();
response.End();
}
The method did pass data (byte[2100217]) and display the pdf in the browser. But the tricky part is that it couldn't be opened from the downloaded file at local after "Save" was used.
Not sure what happened in between. Is this due to the version of Adobe Reader I'm using? It's Adobe Reader XI (version 11.0.10).

opening a file in the browser instead of downloading it

Im using ssrs through a reports server to generate a resultStream byte array using ReportExecutionService.Render() which I am currently serving to the user with the following code. Is there a way I can use this same byte array to automatically open the report in a new browser window instead of going to the save/open dialog?
public void RenderReport (byte[] reportDigits, ReportItem reportItem)
{
HttpResponse response = HttpContext.Current.Response;
response.Clear();
response.ContentType = reportItem.ReportMimeType;
response.AddHeader("Content-Disposition", string.Format("attachment; filename={0}", reportItem.ExportName));
response.OutputStream.Write(reportDigits, 0, reportDigits.Length);
response.End();
}
In the past I have used a separate ReportViewer.aspx page that I would open first then display the report but would like to do it all in code behind if that is possible.
Thanks
It's this line:
response.AddHeader("Content-Disposition", string.Format("attachment; filename={0}", reportItem.ExportName));
Thats causing it to be downloaded. Comment out that line, and as long as the browser can handle the mime type, it will render in the browser window.
Simply change the Header that you are adding to something other than an attachement. Make it the format of your data--and hopefully the browser will recognize it.

Categories

Resources