0

I have a page where I'm simply trying to write a pdf to the screen. Here's what I'm doing:

protected void ViewPDF(string url)
{
    Response.Clear();
    Response.ClearContent();
    Response.ClearHeaders();
    Response.ContentType = "application/pdf";
    Response.TransmitFile(url);
    Response.Flush();
    Response.End();
}

This works in every browser and OS except for Firefox on Mac. Instead of displaying the pdf file in the browser, the browser opens the dialog to download the file, where you can Open it or Save it.

I've also tried this:

protected void ViewPDF(string url)
{    
    Response.Clear();
    Response.ContentType = "application/pdf";

    string path = Server.MapPath(url);
    byte[] data = File.ReadAllBytes(path);
    Response.BinaryWrite(data);
    Response.End();
}

And I get the same result.

Anyone know how to fix this?

Steven
  • 18,761
  • 70
  • 194
  • 296
  • 3
    Does that Firefox have a pdf viewer plug in? FF itself has no native pdf handling facilities, so without a viewer plugin, you'll never get anything EXCEPT the download prompt. – Marc B Oct 29 '12 at 14:55

2 Answers2

1

The browser needs to be able to render any given file format. Firefox (for Mac) does not include a PDF renderer out of the box. It's that simple.

See http://support.mozilla.org/en-US/kb/view-pdf-files-firefox-without-downloading-them.

deceze
  • 510,633
  • 85
  • 743
  • 889
0

You can try changing the content disposition header. There is a full discussion in this post:

Content-Disposition:What are the differences between “inline” and “attachment”?

Community
  • 1
  • 1
JotaBe
  • 38,030
  • 8
  • 98
  • 117