How to show rdlc report as pdf in mozzzilla pdf viewer? - asp.net

I have some asp.net application, which contains 3 rdlc reports. I open those reports in report viewer and it works great. I can download report as pdf file, and also print it from report viewer. Now what I would like to do is this (only if using mozzilla browser): I want to show only pdf file of the report in browser, actually in mozzila pdf viewer. here is the link as an example: http://www.selab.isti.cnr.it/ws-mate/example.pdf (open it in mozzila).
And also i would like to know if this could be done with javascript. Just to mention, i open this reports on button click.
Hope I was clear enough with my question, if you need some more info let me know.

Not javascript but here's how I would do it. For simplicity I'm assuming the report is already loaded into the reportviewer.
In your button click event handler:
//perform check for mozilla... see http://msdn.microsoft.com/library/3yekbd5b
if (browser.Name == mozilla)
{
//get report from viewer
byte[] bytes = ReportViewer1.LocalReport.Render("PDF");
//display pdf in browser
Response.AddHeader("Content-Disposition", "inline; filename=MyReport.pdf");
Response.ContentType = "application/pdf";
Response.BinaryWrite(bytes);
Response.End();
}
Let me know if I missed something but I think understood what you wanted.

Related

ASP.NET "application/pdf": code runs only once

I'm working on a SharePoint 2013 site and I've added the ability to save pages in PDF. The PDF conversion is handled by the third party library SelectPdf.
I managed to get everything to work (rendering and file download), except that the "PDF Download" button that I have on my page works only 1 time. Meaning, the click event on the code behind is fired only once, no matter how many times I click the button (notice that I click it with intervals of 10+ seconds). If I want to download the PDF file again, I have to refresh the page.
I put together a "hello world" example (see below) in order to pinpoint the problem:
protected void lnkPdfDownload_Click(object sender, EventArgs e)
{
Response.Clear();
Response.ClearContent();
Response.ClearHeaders();
Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "attachment;filename=test.pdf");
/************************************ Create PDF File ************************************/
string html = #"<!DOCTYPE html PUBLIC ""-//W3C//DTD XHTML 1.0 Strict//EN"" ""http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"">
<html dir=""ltr"" lang=""en-US"">
<body><h1>Hello World</h1></body>
</html>";
HtmlToPdf converter = new HtmlToPdf();
PdfDocument doc = converter.ConvertHtmlString(html);
byte[] bytes = doc.Save();
Response.OutputStream.Write(bytes, 0, bytes.Length); // ALTERNATIVE: doc.Save(Response.OutputStream);
/************************************ Create PDF File ************************************/
//Response.End(); // This throw a ThreadAbortException, therefore I'm using the alternative code below
Response.Flush();
Response.SuppressContent = true;
HttpContext.Current.ApplicationInstance.CompleteRequest();
}
At the beginning I thought it was Response.End() that caused the issue (by throwing the ThreadAbortException), but I replaced it with other code and I still have the same problem (no exceptions are thrown now).
I don't think the problem is in the SelectPdf library: I can comment out the entire block (between the "Create PDF File" comments), and I still get the same thing (obviously no PDF is generated).
I noticed that, at most, I can successfully click the "download" button up to 2 times (it's rare, and not consistent): the third time nothing happens.
While this isn't a huge deal, I think there is something wrong going on that I'm not seeing. Here is why: after I click the "download" button (and get my PDF file), I am not able to go on edit mode in my SharePoint page. The "loading" message keeps spinning but nothing happens (again, unless I refresh the page).
Has anyone had this problem? I looked online but I couldn't find anything about it.
I'm using Internet Explorer 11 and Chrome 51. Please let me know if you need more information. Thank you.
Are you sure there are not javascript/jquery errors happening when the download button is clicked that prevent the re-clicking of the PDF button and also going into edit mode?
Especially since refreshing the page makes everything work again.

printing rdlc using report viewer 10.0.0.0, print button not showing

I have an rdlc report in an asp.net project.I’m using report viewer 10.0.0.0 to view and print the report. Except for Internet Explorer the print button of the report viewer does not show.
Though in my case, print button does show in IE, it gives the error” Unable to load client print control” when it is pressed. I found similar problems reported for report viewer 2008,but the solutions like, installing the SP 1 did not solved my problem.
Is there a way to enable printing independent of the browser?
Please Help.
You can add your own button and adjust it to the report header and, using jquery and javascript you can print from chrome or firefox
For direct printing on page load:
$(window).load(function() {
var a = document.getElementById("ReportFrame" + reporviwername).contentWindow;
a[1].print();
});
For printing on PrintButton click:
$('.PrintButton').live('click', function() {
var a = document.getElementById("ReportFrame" + reporviwername).contentWindow;
a[1].print();
});
The printer controls in report viewer are implemented as an ActiveX Control. Those are IE specific controls. So, you will not get that option if you use anything other than IE.
If you want a browser independent version, you could embed the report in pdf form.
Pdfs viewers have a print button.
In my experience it works well with most modern browsers. The pdf format too is standard, so your reports will be printed the same, regardless of the browser.
As everyone suggested that Report viewer control only renders with ActiveX control, and many other browsers don't support this so not possible but IE.
So Microsoft updates their supporting features in a recent release after SQL Server Reporting Service 2016 and later version they have updated their dependencies on ActiveX Control.
So you can update your Reporting Services to Latest.
Refer :Updated Report Viewer Control

How to disable Google Chrome's "Chrome PDF Viewer" using Asp.net

due to some unavoidable reasons I need to disable Google Chrome's "Chrome PDF Viewer" and enable the adob PDF viewer. I want to do this from C#.net and asp.net Code. I know it is not possible directly as it is related to change setting's on a client machine but I am ready to ask permission from user if s/he wants to disable the default viewer.
The reason behind this work is that all my PDFs created in iTextSharp are not functioning properly in Google Chrome due to Chrome's default reader. Not all user's can find and disable the plugin manually, hence I want it to be done by code. I need to know that how we can disable the default PDF viewer. AFter this my problem will be solved automatically. pls give me any suggestion about code
Aslong as your embedding the pdf in a html file the following might work for you....
Try changing the type of the embed to type="application/vnd.adobe.pdfxml", I know this isnt what your serving but when I tried it on a normal pdf the plugin didnt choke and showed the pdf using Adobes plugin without having to disable the default (Chromes) reader.
I had to test this on a version of the Adobe plugin that is a bit old as Im on dialup and couldnt be bothered downloading a 50 something meg file just for testing ;). So you should test it on the newest plugin.
Hope it works out for you.
EDIT:
Heres an example page of how to make the pdf take up the full screen like if you just pointed straight to the file...
http://pdfobject.com/markup/examples/full-browser-window.html
...its also the page I did my test on.
Google chrome plugins doesnot change the programming way so just inform to the client like a pop up message
<script type="text/javascript">
function CheckPlugin()
{
var is_chrome = navigator.userAgent.toLowerCase().indexOf('chrome') > -1;
function findPlugin(ext) {
var thisExt, findExt;
for (var n = 0; n < navigator.plugins.length; n++) {
//alert("n value"+ navigator.plugins.length);
for (var m = 0; m < navigator.plugins[n].length; m++) {
//alert("m length:"+navigator.plugins[n].length);
thisExt = navigator.plugins[n][m].description.toLowerCase();
// alert("this exten"+thisExt);
findExt = thisExt.substring(0, thisExt.indexOf(" "));
//alert("findexes"+findExt);
if (findExt == ext)
return (true);
}
}
return (false);
}
if (is_chrome ==true) {
//alert("chrome browser");
if (findPlugin("acrobat")) {
//alert("Adobe Acrobat pdf viewer");
return true;
}
else {
alert("please disable the chrome pdf viewer and enable the Adobe Acrobat PDF viewer \n Please follow the steps:\n 1.Open the new tab 'chrome://plugins/' type the Address. \n 2. Click the Enable link in 'Adobe Acrobat' field. \n 3. click the Disable link in 'Chrome PDF Viewer'. \n 4. Close the tab and you can open the PDf files in chrome browser.");
return false;
}
}
else {
//alert("not chrome");
}
}
</script>
In hyperlink write like this
<asp:HyperLink ID="HyperLink1" runat="server"
NavigateUrl="~/PDFFiles/AGENCY PROFILE APP.pdf" onclick="return CheckPlugin();">Agency profile app</asp:HyperLink>
I think it is more help full.
I use iTextSharp, and Chrome was causing issues when both the Chrome PDF and Adobe were enabled. The submit button would send FDF data back to the server even though the form specified sending the data as XFDF. Setting ContentType to "application/vnd.adobe.pdfxml" solved the problem.
Kudos to PAEz.

download xml file using asp.net

I have created a xml file using c# and I can save it at any location in my machine (in this situation I have saved it on the root of the application with name "temp.xml"), but I want to let it for the user to download it from their browser buy giving a link like-->
"click HERE to download the file."
In Chrome and FireFox it show a new tab with only some values in my body part of the xml file but IE shows the whole xml. I want to download it in my download folder when anybody click on the above link.
thanks in advance for your support.
You need to specifically mention the file type and name. and use the TransmitFile method. This will show the Save As window.
I got the following code from this webpage
Response.ContentType = "image/jpeg";
Response.AppendHeader("Content-Disposition","attachment; filename=SailBig.jpg");
Response.TransmitFile( Server.MapPath("~/images/sailbig.jpg") );
HttpContext.Current.ApplicationInstance.CompleteRequest();
Response.AddHeader("content-disposition", "attachment;filename=temp.xml");
Response.ContentType = "text/xml";
Response.Write(File.ReadAllText(Server.MapPath("~/temp.xml"))); //you may want to write the XML directly to output stream instead of creating an XML file first.
Response.End();
Hope this helps.

pdf will load if use 'save link as' but not if user clicks on the link

After submitting a form, the user is presented with a link to a pdf document.
The link is straight to the document, it is not streamed.
If the user right-clicks and chooses 'save link as,' the document saves and opens fine. However, if the user just clicks on the link, the browser takes a very long time to respond (I'm going to guess it's 3 minutes) and then adobe reader gives the following error:
"the file is damaged and could not be repaired"
This is in Chrome v5, ASP.NET 3.5 and the link is returned inside an UpdatePanel.
it depends on browser settings that are configured for PDF Links. If you change the settings in broweser, you will get the download dialog.
Mozilla Firefox
Open Mozilla Firefox
Click Tools and then Options
Within the Options window click Applications
Select the Content Type you wish to adjust. For example, if you want to change how a .PDF file opens in Firefox, select Adobe Acrobat Document.
In the Action section, change the action to how you wish to open the file. If you want to download .PDF files instead of opening them, select Save file.
Internet Explorer:
You have to right click and click save target as to download.
The other option is, create a seperate asp.net and write below code to download the PDF
private void Page_Load(object sender, System.EventArgs e)
{
//Set the appropriate ContentType.
Response.ContentType = "Application/pdf";
//Get the physical path to the file.
string FilePath = MapPath("acrobat.pdf");
//Write the file directly to the HTTP content output stream.
Response.WriteFile(FilePath);
Response.End();
}
I've had this issue before and the cause was the PDF itself.
Adobe has a slew of causes for this: http://kb2.adobe.com/cps/328/328233.html
FWIW, my PDf issue was solved by opening the PDF in Adobe and going to Document -> Reduce File Size -> Make Compatible with Version 7. (current version - 2)

Resources