Javascript 使用 Adob​​e Reader 10.0 无法在 Internet Explorer 中打开 PDF 文件 - 用户会看到一个空白的灰色屏幕。我该如何为我的用户解决这个问题?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7588262/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-24 02:49:57  来源:igfitidea点击:

PDF files do not open in Internet Explorer with Adobe Reader 10.0 - users get an empty gray screen. How can I fix this for my users?

javascriptasp.net-mvcinternet-exploreradobe-reader

提问by Scott Rippey

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.*.

使用 Adob​​e Reader X(版本 10.0.*)在 Internet Explorer(v 6、7、8、9)中打开 PDF 存在一个已知问题。浏览器窗口加载一个空的灰色屏幕(甚至没有阅读器工具栏)。它适用于 Firefox、Chrome 或 Adob​​e 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!

我发现了几种解决方法。例如,点击“刷新”将正确加载文档。升级到 Adob​​e Reader 10.1.* 或降级到 9.* 也可以解决此问题。
但是,所有这些解决方案都需要用户自行解决。我的大多数用户在看到这个灰色屏幕时感到非常困惑,并最终归咎于 PDF 文件并归咎于网站被破坏了。老实说,在我研究这个问题之前,我也把责任归咎于 PDF!

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-Dispositionheader to attachmentinstead of inline), but my company does not like that solution at all, because we really want these PDF files to display in the browser.

因此,我正在尝试为我的用户找出解决此问题的方法。
我考虑过提供“下载 PDF”链接(将Content-Disposition标题设置为attachment而不是inline),但我的公司根本不喜欢该解决方案,因为我们真的希望这些 PDF 文件显示在浏览器中。

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.

我真的希望有一个对最终用户来说是无缝的解决方案,因为我不能依赖他们知道如何更改他们的 Adob​​e Reader 设置,或自动安装更新。

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.

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

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=_blankso 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 .pdfextension, but we do set the content-dispositionheader with a valid .pdffilename and the inlinesetting.

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

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

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

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):

这是 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);
    }
}

采纳答案by Scott Rippey

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.

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

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:

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

  • 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)
  • Adobe Reader 破解版 (10.0.*)
  • 带有 Internet Explorer 和默认设置“不将加密文件保存到磁盘”的 HTTPS 站点
  • Adobe Reader 设置 - 禁用“在浏览器中显示 PDF 文件”
  • 缓慢的硬件(感谢@ahochhaus)

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

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

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.

我想出的解决方法是将 PDF 文件嵌入到一个空的 HTML 页面中。这很简单: 请参阅 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-indexto show it ... but ...
  • Google Chrome's built-in PDF viewer also displays the "Get Adobe Reader" section on top ofthe PDF, so I had to do browser detection to determine whether to show the "Get Reader".
  • 这会忽略 PDF 的所有用户首选项 - 例如,我个人喜欢在独立的 Adob​​e Reader 中打开 PDF,但会被忽略
  • 如果您没有安装/启用 Adob​​e Reader 插件,这将不起作用,因此我在 html 中添加了一个“获取 Adob​​e Reader”部分,以及一个下载文件的链接,该链接通常被<object />标签完全隐藏, ... 但 ...
  • 在 Internet Explorer 中,如果插件加载失败,空对象仍然会隐藏“Get Adob​​e Reader”部分,所以我不得不设置z-index显示它......但是......
  • Google Chrome 的内置 PDF 查看器还在 PDF顶部显示“Get Adob​​e Reader”部分,因此我不得不进行浏览器检测以确定是否显示“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 embeddedoption 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 GetPDFAction, we look for the embed=truecookie. This determines whether we return the PDF file, or if we return a View of HTML with the embedded PDF.

这是一个巨大的警告列表。我相信它涵盖了所有基础,但我绝对不习惯将其应用于每个用户(其中​​大多数没有问题)。
因此,我们决定仅embedded在用户选择加入时才执行此选项。在我们的 PDF 页面上,我们有一个部分显示“在查看 PDF 时遇到问题?”,它允许您将设置更改为“嵌入”,然后我们将该设置存储在 cookie 中。
在我们的GetPDFAction 中,我们寻找embed=truecookie。这决定了我们是返回 PDF 文件,还是返回带有嵌入 PDF 的 HTML 视图。

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!

啊。这甚至不如编写兼容 IE6 的 JavaScript 有趣。
我希望有同样问题的其他人知道他们并不孤单,可以找到安慰!

回答by ahochhaus

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.

根据我的测试,灰屏仅在较慢的机器上触发 [1]。迄今为止,我还无法在较新的硬件上重新创建它 [2]。我所有的测试都是在 IE8 中使用 Adob​​e Reader 10.1.2 进行的。对于我的测试,我关闭了 SSL 并删除了所有可能禁用缓存的标头。

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)

1) 导航到链接到 PDF 的页面
2) 在新窗口或选项卡中打开 PDF(通过上下文菜单或 target="_blank")
3) 在我的测试中,此 PDF 将无错误地打开(但是我已收到用户报告,表明首次加载 PDF 失败)
4) 关闭新打开的窗口或选项卡
5) 在新窗口或选项卡中(再次)打开 PDF
6) 此 PDF 不会打开,而是仅显示“灰色”屏幕”由第一个用户提到(所有后续加载的 PDF 也不会显示 - 直到所有浏览器窗口关闭)

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).

我使用从不同来源生成的几个不同的 PDF 文件(静态和动态)执行了上述测试,并且在执行上述步骤时(在“慢速”计算机上)总是会出现灰屏问题。

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.

为了缓解我的应用程序中的问题,我“拆除”了链接到 PDF 的页面(逐个删除部分,直到不再出现灰屏)。在我的特定应用程序(建立在闭包库上)中,删除对 goog.userAgent.adobeReader [3] 的所有引用似乎已经解决了这个问题。这个确切的解决方案不适用于 jquery 或 .net MVC,但也许该过程可以帮助您隔离问题的根源。我还没有花时间确定 goog.userAgent.adobeReader 的哪个特定部分触发了 Adob​​e Reader 中的错误,但 jquery 可能具有与closure-library 中使用的类似的插件检测代码。

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

[1] 机器灰屏:
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

[2] 机器没有出现灰屏:
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

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

回答by Todd Smith

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

我在 MVC1 首次发布时遇到了这个问题。请参阅生成 PDF,关于 Cache-Control 标头的IE 和 HTTPS 错误

回答by FCWatson

For Win7 Acrobat Pro X

对于 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.

由于我在没有重新检查之后是否仍然存在问题的情况下完成了所有这些操作,因此我不确定其中哪些确实解决了问题,但其中一个确实解决了问题。事实上,在执行 #3 并重新启动后,它运行良好。

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

仅供参考:以下是我逐步完成维修的顺序。

  1. Go to Control Panel> folders options under each of the General, Viewand SearchTabs click the Restore Defaultsbutton and the Reset Foldersbutton

  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.

  1. 转到Control Panel每个General,ViewSearch选项卡下的 > 文件夹选项,然后单击Restore Defaults按钮和Reset Folders按钮

  2. 转到Internet Explorer, Tools> Options> Advanced> Reset(我不需要删除个人设置)

  3. 打开Acrobat Pro X,在Edit> Preferences> 下General
    在页面底部选择Default PDF Handler。我选择了Adobe Pro X,然后单击Apply

You may be asked to reboot (I did).

您可能会被要求重新启动(我做到了)。

Best Wishes

最好的祝愿

回答by David Alexandru

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"');

就我而言,解决方案非常简单。我添加了这个标题,浏览器在每次测试中都打开了这个文件。header('Content-Disposition: 附件; filename="filename.pdf"');

回答by Lisa

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 ...

我有这个问题。重新安装最新版本的 Adob​​e Reader 没有任何作用。Adobe Reader 可以在 Chrome 中运行,但不能在 IE 中运行。这对我有用...

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.

1) 进入IE的工具-->兼容性视图菜单。
2) 输入包含您希望查看的 PDF 的网站。单击确定。
3) 重新启动 IE 4) 转到您输入的网站并选择 PDF。它应该出现。
5)返回兼容性视图并删除您所做的条目。
6) Adob​​e Reader 现在可以在所有网站的 IE 中正常工作。

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.

这是一个奇怪的修复,但它对我有用。重新安装后,我需要通过 Adob​​e 接受屏幕,该屏幕仅在我执行兼容性视图技巧后才会出现。一旦被接受,它似乎无处不在。很薄的东西。希望这可以帮助某人。

回答by thecoolmacdude

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

即使更新到最新的 Adob​​e Reader 版本,我们也遇到了这个问题。

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.hrefmethod.
  • 使用免费版 Foxit Reader 应用程序代替 Adob​​e Reader
  • 但是,由于我们的大多数客户都使用 Adob​​e Reader,因此我们不再要求用户使用 Foxit Reader,而是开始使用window.open(url)打开 pdf 而不是window.location.href = url. 当使用该window.location.href方法打开 pdf 时,由于某种原因,Adobe 在不同的 iframe 中丢失了文件句柄。

回答by puterfx

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.

我意识到这是一个相当晚的帖子,但仍然是 OP 的可能解决方案。我在 Win 7 上使用 IE9,并且在尝试在线打开 pdf 银行和信用卡对帐单时,几个月来一直有 Adob​​e Reader 的灰屏问题。我可以在 Firefox 或 Opera 中打开所有内容,但不能在 IE 中打开。我终于尝试了 PDF-Viewer,在其首选项中将其设置为默认的 pdf 查看器,没有更多问题。我敢肯定还有其他免费的查看器,比如 Foxit、PDF-Xchange 等,它们会比 Reader 提供更好的结果,而且头痛更少。Adobe 就像其他一些开发软件的大公司一样,他们在接受或离开的基础上……所以我离开了。

回答by ahochhaus

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).

尝试更多,我的应用程序(调用 goog.userAgent.adobeReader)的根本原因是通过页面上的 ActiveXObject 访问 Adob​​e Reader,并带有指向 PDF 的链接。这个最小的测试用例会导致我出现灰屏(但是删除 ActiveXObject 不会导致灰屏)。

<!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

有关此最小测试用例的视频示例,请参阅:http: //youtu.be/IgEcxzM6Kck

回答by darioo

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.

您的用户第一次打开 pdf 时,使用 Javascript 您会弹出一个基本上说“如果您看不到您的文档,请单击此处”的弹出窗口。将“HERE”变成一个大按钮,它会向您的用户解释问题所在。还要制作另一个按钮“一切都很好”。如果用户点击这个,你会记住它,所以它不会在以后显示。

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.

我正在努力实用。不遗余力地尝试为 Adob​​e Reader 版本的一小部分“正确”解决此类问题对我来说听起来效率不高。