我已经发现了几个解决方法。例如,单击“刷新”会正确加载文档。升级到Adobe Reader 10.1.*,或降级到9.*也可以解决该问题。
然而,所有这些解决方案都要求用户自行解决。我的大多数用户看到这个灰色屏幕会感到非常困惑,并且会责怪PDF文件和网站出现问题。说实话,在我调查问题之前,我也责怪PDF文件!
所以,我正在尝试找出一种为我的用户解决此问题的方法。我考虑提供一个“下载PDF”链接(将Content-Disposition标头设置为附件而不是内联),但我的公司根本不喜欢这个解决方案,因为我们真的希望这些PDF文件在浏览器中显示。
有其他人遇到过这个问题吗?
有哪些可能的解决方案或解决方法?
我真的希望有一种对最终用户来说无缝的解决方案,因为我不能指望他们知道如何更改其Adobe Reader设置,或自动安装更新。
这里是可怕的灰屏:
编辑:截图已从文件服务器中删除! 抱歉!
该图像是一个带有常规工具栏的浏览器窗口,但是有着纯灰色背景,没有任何用户界面。
背景信息:
尽管我认为以下信息与我的问题无关,但我会将它包含在内供参考:
这是一个ASP.NET MVC应用程序,并且具有jQuery。
PDF文件链接具有target=_blank,以便在新窗口中打开。
PDF文件是动态生成的,并且所有内容标头都已适当设置。URL不包括.pdf扩展名,但我们确实使用有效的.pdf文件名和inline设置设置了content-disposition标头。
编辑:下面是我用来提供PDF文件的源代码。
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);
}
}
Content-Type
,Content-Disposition
等)。整个文件也被流式传输了。由于问题可以通过“刷新”或更新Reader来解决,因此可以推断PDF文件和传输工作正常。 - Scott Rippey