使用Adobe Reader 10.0在Internet Explorer中无法打开PDF文件 - 用户将获得一个空灰色屏幕.如何为我的用户解决此问题?

Sco*_*pey 30 javascript asp.net-mvc internet-explorer adobe-reader

使用Adobe Reader X(版本10.0.*)在Internet Explorer(v 6,7,8,9)中打开PDF存在一个已知问题.浏览器窗口加载一个空的灰色屏幕(甚至没有Reader工具栏).它适用于Firefox,Chrome或Adobe Reader 10.1.*.

我发现了几个解决方法.例如,点击"刷新"将正确加载文档.升级到Adobe Reader 10.1.*,或降级到9.*,也解决了这个问题.
但是,所有这些解决方案都要求用户弄明白.我的大多数用户在看到这个灰色屏幕时非常困惑,最终指责PDF文件并指责网站被破坏.老实说,在我研究这个问题之前,我也责备了PDF!

所以,我试图找到一种方法来解决我的用户的这个问题.
我考虑过提供一个"下载PDF"链接(将Content-Disposition标题设置为attachment而不是inline),但我的公司根本不喜欢这个解决方案,因为我们真的希望这些PDF文件能够在浏览器中显示.

还有其他人遇到过这个问题吗?

有哪些可能的解决方案或解决方法?

我真的希望找到一个与最终用户无缝的解决方案,因为我不能依赖它们来了解如何更改其Adobe Reader设置,或者自动安装更新.

这是可怕的灰色屏幕:
编辑:截图已从文件服务器中删除!抱歉!
该图像是一个浏览器窗口,带有常规工具栏,但是背景为灰色背景,没有任何UI.

背景信息:
虽然我不认为以下信息与我的问题有关,但我会将其包含在内以供参考:
这是一个ASP.NET MVC应用程序,并且提供了jQuery.
PDF文件的链接已target=_blank在新窗口中打开.
PDF文件正在即时生成,并且所有内容标题都已正确设置.URL不包含.pdf扩展名,但我们会content-disposition使用有效的.pdf文件名和inline设置来设置标头.

编辑:这是我用来提供PDF文件的源代码.

首先,控制器行动:

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

这是ActionResult(PdfResult,继承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);
    }
}
Run Code Online (Sandbox Code Playgroud)

Sco*_*pey 30

问这个问题已经有4个月了,我还没有找到一个好的解决方案.
但是,我确实找到了一个不错的解决方法,如果其他人遇到同样的问题我会分享.
如果我取得进一步进展,我也会尝试更新这个答案.

首先,我的研究表明,有几种可能的用户设置和网站设置组合会导致各种PDF显示问题.这些包括:

  • Adobe Reader的破碎版(10.0.*)
  • 具有Internet Explorer的HTTPS站点和默认设置"不将加密文件保存到磁盘"
  • Adobe Reader设置 - 禁用"在我的浏览器中显示PDF文件"
  • 慢硬件(感谢@ahochhaus)

我花了一些时间在pdfobject.com上研究PDF显示选项,这是一个很好的资源,我学到了很多东西.

我想出的解决方法是将PDF文件嵌入到空的HTML页面中.这很简单: 请参阅pdfobject.com上的一些类似示例.

<html>
    <head>...</head>
    <body>
        <object data="/pdf/sample.pdf" type="application/pdf" height="100%" width="100%"></object>
    </body>
</html>
Run Code Online (Sandbox Code Playgroud)

但是,这里有一个警告列表:

  • 这忽略了PDF的所有用户首选项 - 例如,我个人喜欢在独立的Adobe Reader中打开PDF,但是忽略了
  • 如果你没有安装/启用Adobe Reader插件,这不起作用,所以我在html中添加了一个"Get Adob​​e Reader"部分,以及一个下载文件的链接,该文件通常被<object />标签完全隐藏, ......但......
  • 在Internet Explorer中,如果插件无法加载,空对象仍将隐藏"Get Adob​​e Reader"部分,因此我必须设置z-index为显示它...但是...
  • 谷歌浏览器内置的PDF查看器还显示"获取Adobe Reader"部分之上的PDF,所以我不得不做浏览器检测,以确定是否显示"获取读者".

这是一个巨大的警告清单.我相信它涵盖了所有的基础,但我绝对不习惯将它应用于每个用户(大多数人没有问题).
因此,embedded如果用户选择使用它,我们决定只执行此选项.在我们的PDF页面上,我们有一个部分说"查看PDF文件有问题?",它允许您将设置更改为"嵌入式",并将该设置存储在cookie中.
在我们的GetPDFAction中,我们寻找embed=truecookie.这决定了我们是返回PDF文件,还是返回带有嵌入PDF的HTML视图.

啊.这比编写兼容IE6的JavaScript更有趣.
我希望有同样问题的其他人能够在他们并不孤单的情况下找到安慰!