使用 Adobe Reader X(版本 10.0.*)在 Internet Explorer(v 6、7、8、9)中打开 PDF 时存在一个已知问题。浏览器窗口加载一个空的灰色屏幕(甚至没有阅读器工具栏)。它与 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 文件的源代码。
一、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);
}
}