使用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
header 设置为attachment
而不是inline
),但是我的公司根本不喜欢这种解决方案,因为我们确实希望这些PDF文件显示在浏览器中。
还有其他人遇到过这个问题吗?
有哪些可能的解决方案或解决方法?
我真的很希望能找到一种与最终用户无缝的的解决方案,因为我不能依靠他们知道如何更改其Adobe Reader设置或自动安装更新。
这是可怕的灰屏:
编辑:屏幕快照已从文件服务器中删除!对不起!
该图像是一个浏览器窗口,带有常规工具栏,但背景为纯灰色,没有任何UI。
背景信息:
尽管我认为以下信息与我的问题无关,但我将其包括在内以供引用:
这是一个ASP.NET MVC应用程序,并且具有jQuery。
PDF文件的链接带有target=_blank
,因此它将在新窗口中打开。
PDF文件正在即时生成,并且所有内容 header 均已适当设置。
该URL不包括.pdf
扩展名,但我们使用有效的content-disposition
文件名和.pdf
设置来设置inline
header 。
编辑:这是我用来提供PDF文件的源代码。
首先, Controller Action :
public ActionResult ComplianceCertificate(int id){
byte[] pdfBytes = ComplianceBusiness.GetCertificate(id);
return new PdfResult(pdfBytes, false, "Compliance Certificate {0}.pdf", id);
}
这是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);
}
}
最佳答案
问这个问题已经四个月了,我仍然没有找到一个好的解决方案。
但是,我确实找到了一个不错的解决方法,以防他人遇到相同的问题,我将与大家分享。
如果我取得进一步的进展,我也会尝试更新此答案。
首先,我的研究表明,用户设置和站点设置的几种可能组合会导致各种PDF显示问题。这些包括:
我花了一些时间在pdfobject.com上研究PDF显示选项,这是一个很好的资源,我学到了很多东西。
我想出的解决方法是将PDF文件嵌入一个空的HTML页面中。这很简单: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>
但是,以下是警告说明:
<object />
会完全隐藏该文件标签,但... z-index
来显示它……但是... 这是一个警告的巨大 list 。我相信它涵盖了所有基础,但是我绝对不愿意将此应用到每个用户(大多数用户都没有问题)。
因此,我们决定仅在用户选择加入时才执行此
embedded
选项。在我们的PDF页面上,有一个部分显示“在查看PDF时遇到问题了吗?”,可让您将设置更改为“嵌入式”,并将该设置存储在cookie中。在
GetPDF
操作中,我们寻找embed=true
cookie。这确定我们是否返回PDF文件,或者是否返回带有嵌入式PDF的HTML View 。啊。这比编写与IE6兼容的JavaScript还要有趣。
我希望遇到同样问题的其他人知道自己并不孤单,可以找到安慰!