31

There is a known issue with opening a PDF in Internet Explorer (v 6, 7, 8, 9) with Adobe Reader X (version 10.0.*). The browser window loads with an empty gray screen (and doesn't even have a Reader toolbar). It works perfectly fine with Firefox, Chrome, or with Adobe Reader 10.1.*.

I have discovered several workarounds. For example, hitting "Refresh" will load the document properly. Upgrading to Adobe Reader 10.1.*, or downgrading to 9.*, fixes the issue too.
However, all of these solutions require the user to figure it out. Most of my users get very confused at seeing this gray screen, and end up blaming the PDF file and blaming the website for being broken. Honestly, until I researched the issue, I blamed the PDF too!

So, I am trying to figure out a way to fix this issue for my users.
I've considered providing a "Download PDF" link (that sets the Content-Disposition header to attachment instead of inline), but my company does not like that solution at all, because we really want these PDF files to display in the browser.

Has anyone else experienced this issue?

What are some possible solutions or workarounds?

I'm really hoping for a solution that is seamless to the end-user, because I can't rely on them to know how to change their Adobe Reader settings, or to automatically install updates.

Here's the dreaded Gray Screen:
Edit: screenshot was deleted from file server! Sorry!
The image was a browser window, with the regular toolbar, but a solid gray background, no UI whatsoever.

Background info:
Although I don't think the following information is related to my issue, I'll include it for reference:
This is an ASP.NET MVC application, and has jQuery available.
The link to the PDF file has target=_blank so that it opens in a new window.
The PDF file is being generated on-the-fly, and all the content headers are being set appropriately. The URL does NOT include the .pdf extension, but we do set the content-disposition header with a valid .pdf filename and the inline setting.

Edit: Here is the source code that I'm using to serve up the PDF files.

First, the Controller Action:

public ActionResult ComplianceCertificate(int id){
    byte[] pdfBytes = ComplianceBusiness.GetCertificate(id);
    return new PdfResult(pdfBytes, false, "Compliance Certificate {0}.pdf", id);
}

And here is the ActionResult (PdfResult, inherits System.Web.Mvc.FileContentResult):

using System.Net.Mime;
using System.Web.Mvc;
/// <summary>
/// Returns the proper Response Headers and "Content-Disposition" for a PDF file,
/// and allows you to specify the filename and whether it will be downloaded by the browser.
/// </summary>
public class PdfResult : FileContentResult
{
    public ContentDisposition ContentDisposition { get; private set; }

    /// <summary>
    /// Returns a PDF FileResult.
    /// </summary>
    /// <param name="pdfFileContents">The data for the PDF file</param>
    /// <param name="download">Determines if the file should be shown in the browser or downloaded as a file</param>
    /// <param name="filename">The filename that will be shown if the file is downloaded or saved.</param>
    /// <param name="filenameArgs">A list of arguments to be formatted into the filename.</param>
    /// <returns></returns>
    [JetBrains.Annotations.StringFormatMethod("filename")]
    public PdfResult(byte[] pdfFileContents, bool download, string filename, params object[] filenameArgs) 
        : base(pdfFileContents, "application/pdf")
    {
        // Format the filename:
        if (filenameArgs != null && filenameArgs.Length > 0)
        {
            filename = string.Format(filename, filenameArgs);
        }

        // Add the filename to the Content-Disposition
        ContentDisposition = new ContentDisposition
                                 {
                                     Inline = !download,
                                     FileName = filename,
                                     Size = pdfFileContents.Length,
                                 };
    }

    protected override void WriteFile(System.Web.HttpResponseBase response)
    {
        // Add the filename to the Content-Disposition
        response.AddHeader("Content-Disposition", ContentDisposition.ToString());
        base.WriteFile(response);
    }
}
Scott Rippey
  • 15,614
  • 5
  • 70
  • 85
  • 1
    In general you can't *guarantee* that and end-user browser will open a pdf document in any particular way. I understand your question however and I think it's an interesting one. – Pointy Sep 28 '11 at 19:11
  • You're right ... in fact, if the user opens the PDF ANY other way, it works fine! But the DEFAULT way is a show-stopper, and that's where my problem lies. – Scott Rippey Sep 28 '11 at 19:16
  • Use an http sniffer to see if you serve the correct mime types - you may set them correctly and then your server mess it up. Also make sure that you either STREAM it correctly or that the file is completely sent to the browser (log files). Lastly output the file to disk and serve the completed file as a temporary measure – mplungjan Sep 28 '11 at 20:00
  • @mplungjan Thanks for the suggestions ... I used Fiddler to inspect the HTTP header, and everything looks exactly right (`Content-Type`, `Content-Disposition`, etc). The full file was streamed too. Since the issue is fixed by either "refresh" or by updating Reader, it stands to reason that the PDF file and transport are working fine. – Scott Rippey Sep 28 '11 at 20:34
  • You are clearing the Response befor sending etc? What exactly is the code your using to send the PDF? – Steve Sep 29 '11 at 14:10
  • @Steve I'm telling you, I highly doubt the issue is with the PDF file or with the transport method. The issue is specific to IE with Reader 10.0.\*. That being said, I have modified the original question to include the `PdfResult` class responsible for returning the result. – Scott Rippey Sep 29 '11 at 16:29
  • 2
    For what it's worth, I've experienced a problem earily similar to this. It turns out, we were emitting the pdf file AND html in the response. Certain combinations of IE and Adobe Reader (X I believe) choked on this. Make sure you are not emitting any HTML. – Aaron Daniels Sep 29 '11 at 16:44
  • can you add a .pdf before the ? or # in the url? – mplungjan Sep 29 '11 at 17:16
  • @AaronDaniels: That's a good point, but I did verify using Fiddler that the PDF file is transmitted correctly -- the response starts with `%PDF` and ends with `%%EOF`, and the content length also matches the response length. – Scott Rippey Sep 29 '11 at 18:43
  • @mplungjan: At one point, I added the `.pdf` extension to my route, which created a URL like `ComplianceCertificate.pdf?id=1`. However, I removed that, and I don't remember why. I am considering retesting this scenario, because it's possible it might have an effect. – Scott Rippey Sep 29 '11 at 18:44
  • 3
    Sometimes IE needs all the help it can get. – mplungjan Sep 30 '11 at 04:30
  • @mplungjan: Ok, I added the `.pdf` extension to the url, but it did not make a difference for this issue. – Scott Rippey Sep 30 '11 at 23:25

10 Answers10

31

It's been 4 months since asking this question, and I still haven't found a good solution.
However, I did find a decent workaround, which I will share in case others have the same issue.
I will try to update this answer, too, if I make further progress.

First of all, my research has shown that there are several possible combinations of user-settings and site settings that cause a variety of PDF display issues. These include:

  • Broken version of Adobe Reader (10.0.*)
  • HTTPS site with Internet Explorer and the default setting "Don't save encrypted files to disk"
  • Adobe Reader setting - disable "Display PDF files in my browser"
  • Slow hardware (thanks @ahochhaus)

I spent some time researching PDF display options at pdfobject.com, which is an EXCELLENT resource and I learned a lot.

The workaround I came up with is to embed the PDF file inside an empty HTML page. It is very simple: See some similar examples at pdfobject.com.

<html>
    <head>...</head>
    <body>
        <object data="/pdf/sample.pdf" type="application/pdf" height="100%" width="100%"></object>
    </body>
</html>

However, here's a list of caveats:

  • This ignores all user-preferences for PDFs - for example, I personally like PDFs to open in a stand-alone Adobe Reader, but that is ignored
  • This doesn't work if you don't have the Adobe Reader plugin installed/enabled, so I added a "Get Adobe Reader" section to the html, and a link to download the file, which usually gets completely hidden by the <object /> tag, ... but ...
  • In Internet Explorer, if the plugin fails to load, the empty object will still hide the "Get Adobe Reader" section, so I had to set the z-index to show it ... but ...
  • Google Chrome's built-in PDF viewer also displays the "Get Adobe Reader" section on top of the PDF, so I had to do browser detection to determine whether to show the "Get Reader".

This is a huge list of caveats. I believe it covers all the bases, but I am definitely not comfortable applying this to EVERY user (most of whom do not have an issue).
Therefore, we decided to ONLY do this embedded option if the user opts-in for it. On our PDF page, we have a section that says "Having trouble viewing PDFs?", which lets you change your setting to "embedded", and we store that setting in a cookie.
In our GetPDF Action, we look for the embed=true cookie. This determines whether we return the PDF file, or if we return a View of HTML with the embedded PDF.

Ugh. This was even less fun than writing IE6-compatible JavaScript.
I hope that others with the same problem can find comfort knowing that they're not alone!

Scott Rippey
  • 15,614
  • 5
  • 70
  • 85
  • I know this is old, but I've tryied your "embebed pdf" solution and it seems to work. Except the `height="100%" width="100%"` part. It doesn't seem to work and the PDF is showed with no height. I've tryied some CSS too, but nothing works. – Daniel Marín Oct 06 '15 at 09:31
3

I don't have an exact solution, but I'll post my experiences with this in case they help anyone else.

From my testing, the gray screen is only triggered on slower machines [1]. To date, I have not been able to recreate it on newer hardware [2]. All of my tests have been in IE8 with Adobe Reader 10.1.2. For my tests I turned off SSL and removed all headers that could have disabled caching.

To recreate the gray screen, I followed the following steps:

1) Navigate to a page that links to a PDF
2) Open the PDF in a new window or tab (either via the context menu or target="_blank")
3) In my tests, this PDF will open without error (however I have received user reports indicating failure on the first PDF load)
4) Close the newly opened window or tab
5) Open the PDF (again) in a new window or tab
6) This PDF will not open, but instead only show the "gray screen" mentioned by the first user (all subsequent PDFs that are loaded will also not display -- until all browser windows are closed)

I performed the above test with several different PDF files (both static and dynamic) generated from different sources and the gray screen issue always occurs when following the above steps (on the "slow" computer).

To mitigate the problem in my application, I "tore down" the page that links to the PDF (removed parts piece by piece until the gray screen no longer occurred). In my particular application (built on closure-library) removing all references to goog.userAgent.adobeReader [3] appears to have fixed the issue. This exact solution won't work with jquery or .net MVC but maybe the process can help you isolate the source of the issue. I have not yet taken the time to isolate which particular portion of goog.userAgent.adobeReader triggers the bug in Adobe Reader, but it is likely that jquery might have similar plugin detection code to that used in closure-library.

[1] Machine experiencing gray screen:
Win Server '03 SP3
AMD Sempron 2400+ at 1.6GHz
256MB memory

[2] Machine not experiencing gray screen:
Win XP x64 SP2
AMD Athlon II X4 620 at 2.6 GHz
4GB memory

[3] http://closure-library.googlecode.com/svn/docs/closure_goog_useragent_adobereader.js.source.html

ahochhaus
  • 392
  • 2
  • 12
  • Thank you very much for describing your issue with such great detail! For me, this is STILL an issue, and I have found several ways to reproduce it. I'll write an answer describing my current workaround, which might help you as well. – Scott Rippey Jan 24 '12 at 19:59
  • Also, just had a quick deja-vu moment, I think that you described a symptom I didn't realize ... the PDF loads correctly the first time, but not again for all subsequent browser sessions. I think I remember the same behavior. – Scott Rippey Jan 24 '12 at 20:05
  • Thanks Scott, an update describing your debugging history and current work around could be very helpful. – ahochhaus Jan 24 '12 at 21:41
1

For Win7 Acrobat Pro X

Since I did all these without rechecking to see if the problem still existed afterwards, I am not sure which on of these actually fixed the problem, but one of them did. In fact, after doing the #3 and rebooting, it worked perfectly.

FYI: Below is the order in which I stepped through the repair.

  1. Go to Control Panel > folders options under each of the General, View and Search Tabs click the Restore Defaults button and the Reset Folders button

  2. Go to Internet Explorer, Tools > Options > Advanced > Reset ( I did not need to delete personal settings)

  3. Open Acrobat Pro X, under Edit > Preferences > General.
    At the bottom of page select Default PDF Handler. I chose Adobe Pro X, and click Apply.

You may be asked to reboot (I did).

Best Wishes

Littm
  • 4,923
  • 4
  • 30
  • 38
FCWatson
  • 11
  • 1
  • 1
    Thanks for the input, but I think you missed the point ... the problem is that the people trying to view these PDFs are not computer literate ... they don't update their apps, they don't know how to change their preferences, and they are blaming ME for their woes. So I want to figure out how to solve their problem from my end. – Scott Rippey Oct 01 '12 at 04:42
  • I ran into this issue recently and this was the only way I could find to fix the problem. The behavior I was seeing was IE would always act like Reader wasn't installed. So on my page with instructions on how to install Reader I just added text saying if you have Reader installed perform the steps in #2 above. – Lane Goolsby Sep 29 '14 at 15:37
1

In my case the solution was quite simple. I added this header and the browsers opened the file in every test. header('Content-Disposition: attachment; filename="filename.pdf"');

1

I had this problem. Reinstalling the latest version of Adobe Reader did nothing. Adobe Reader worked in Chrome but not in IE. This worked for me ...

1) Go to IE's Tools-->Compatibility View menu.
2) Enter a website that has the PDF you wish to see. Click OK.
3) Restart IE 4) Go to the website you entered and select the PDF. It should come up.
5) Go back to Compatibility View and delete the entry you made.
6) Adobe Reader works OK now in IE on all websites.

It's a strange fix, but it worked for me. I needed to go through an Adobe acceptance screen after reinstall that only appeared after I did the Compatibility View trick. Once accepted, it seemed to work everywhere. Pretty flaky stuff. Hope this helps someone.

xlembouras
  • 8,215
  • 4
  • 33
  • 42
Lisa
  • 11
  • 1
  • 1
    Thank you, this might help to identify the problem ... perhaps the "gray screen" is caused by the application trying but failing to show a first-run message. However, the original question is "how do I fix this" from the developer's point of view, not the user's. – Scott Rippey May 27 '14 at 20:44
1

I ran into this issue around the time MVC1 was first released. See Generating PDF, error with IE and HTTPS regarding the Cache-Control header.

Community
  • 1
  • 1
Todd Smith
  • 17,084
  • 11
  • 59
  • 78
  • Thanks for the link. Although the symptoms aren't quite the same, I am going to try a couple of those solutions and see if it changes anything for my problem. – Scott Rippey Oct 01 '11 at 21:05
0

I realize this is a rather late post but still a possible solution for the OP. I use IE9 on Win 7 and have been having Adobe Reader's grey screen issues for several months when trying to open pdf bank and credit card statements online. I could open everything in Firefox or Opera but not IE. I finally tried PDF-Viewer, set it as the default pdf viewer in its preferences and no more problems. I'm sure there are other free viewers out there, like Foxit, PDF-Xchange, etc., that will give better results than Reader with less headaches. Adobe is like some of the other big companies that develop software on a take it or leave it basis ... so I left it.

puterfx
  • 1
  • 1
  • Thanks for the info! I'm sure many people have had the same experience as yours ... and I bet most users blame the website (instead of Adobe). – Scott Rippey Jun 19 '13 at 23:29
0

We were getting this issue even after updating to the latest Adobe Reader version.

Two different methods solved this issue for us:

  • Using the free version of Foxit Reader application in place of Adobe Reader
  • But, since most of our clients use Adobe Reader, so instead of requiring users to use Foxit Reader, we started using window.open(url) to open the pdf instead of window.location.href = url. Adobe was losing the file handle on for some reason in different iframes when the pdf was opened using the window.location.href method.
thecoolmacdude
  • 2,036
  • 1
  • 23
  • 38
0

Hm, would it be possible to simply do this:

The first time your user opens a pdf, using Javascript you make a popout that basically says "If you cannot see your document, please click HERE". Make "HERE" a big button where it will explain to your user what's the problem. Also make another button "everything's fine". If the user clicks on this one, you remember it, so it isn't displayed in the future.

I'm trying to be practical. Going to great lengths trying to solve this kind of problem "properly" for a small subset of Adobe Reader versions doesn't sound very productive to me.

darioo
  • 46,442
  • 10
  • 75
  • 103
  • Acrobat reader X or 10 is not going to be a small subset in all IE versions – mplungjan Sep 28 '11 at 20:01
  • @darioo I agree, it isn't very practical to create a huge fix for a small problem. Hopefully the issue will dwindle as people update Reader. However, it is currently affecting many users, and it affects them in a significant way. I am really hoping for a "proper" solution -- "proper" meaning that the user remains unaware of the problem. – Scott Rippey Sep 28 '11 at 20:19
0

Experimenting more, the underlying cause in my app (calling goog.userAgent.adobeReader) was accessing Adobe Reader via an ActiveXObject on the page with the link to the PDF. This minimal test case causes the gray screen for me (however removing the ActiveXObject causes no gray screen).

<!DOCTYPE html>
<html lang="en">
  <head>
    <title>hi</title>
    <meta charset="utf-8">
  </head>
  <body>
    <script>
      new ActiveXObject('AcroPDF.PDF.1');
    </script>
    <a target="_blank" href="http://partners.adobe.com/public/developer/en/xml/AdobeXMLFormsSamples.pdf">link</a>
  </body>
</html>

I'm very interested if others are able to reproduce the problem with this test case and following the steps from my other post ("I don't have an exact solution...") on a "slow" computer.

Sorry for posting a new answer, but I couldn't figure out how to add a code block in a comment on my previous post.

For a video example of this minimal test case, see: http://youtu.be/IgEcxzM6Kck

ahochhaus
  • 392
  • 2
  • 12
  • Thanks for the screen capture! For what it's worth, no, I couldn't reproduce that error with your test. I have IE8, Reader 10.1.1, and putting my 1.6Ghz computer "under load" made the PDF take ~10 seconds, but it still loaded. – Scott Rippey Jan 25 '12 at 07:34
  • Also, when I get the gray screen, I can hit "Refresh" and it will load correctly. What happens when you try that? – Scott Rippey Jan 25 '12 at 16:07
  • Good ideas. I see the same behavior with the small file (first load works, gray screen on 2nd load). When I get the gray screen, pressing refresh successfully displays the PDF. If I comment out the ActiveXObject I get no gray screen (on first load, second load or refresh). – ahochhaus Jan 25 '12 at 16:38
  • I tried this test case on a few different versions of Adobe Reader. I _do not_ get a gray screen on 10.1.3 or 9.5.0. However, I _do_ get the gray screen on 10.1.2 (every time). If anyone has time, it could be helpful to know which [versions](ftp://ftp.adobe.com/pub/adobe/reader/win/10.x/) others are having problems with. – ahochhaus Apr 26 '12 at 17:13