Javascript PDF文件不能在使用Adobe Reader 10.0的Internet Explorer中打开-用户会看到一个空的灰色屏幕。如何为我的用户修复此问题?
使用AdobeReaderX(版本10.0.*)在Internet Explorer(v6、7、8、9)中打开PDF时存在一个已知问题。浏览器窗口加载一个空的灰色屏幕(甚至没有阅读器工具栏)。它与Firefox、Chrome或AdobeReader10.1*配合使用非常好 我发现了几个变通办法。例如,点击“刷新”将正确加载文档。升级到Adobe Reader 10.1.*或降级到9.*也可以解决此问题。Javascript PDF文件不能在使用Adobe Reader 10.0的Internet Explorer中打开-用户会看到一个空的灰色屏幕。如何为我的用户修复此问题?,javascript,asp.net-mvc,internet-explorer,adobe-reader,Javascript,Asp.net Mvc,Internet Explorer,Adobe Reader,使用AdobeReaderX(版本10.0.*)在Internet Explorer(v6、7、8、9)中打开PDF时存在一个已知问题。浏览器窗口加载一个空的灰色屏幕(甚至没有阅读器工具栏)。它与Firefox、Chrome或AdobeReader10.1*配合使用非常好 我发现了几个变通办法。例如,点击“刷新”将正确加载文档。升级到Adobe Reader 10.1.*或降级到9.*也可以解决此问题。 然而,所有这些解决方案都需要用户来解决。我的大多数用户在看到这个灰色屏幕时都会感到非常困惑,
然而,所有这些解决方案都需要用户来解决。我的大多数用户在看到这个灰色屏幕时都会感到非常困惑,并最终指责PDF文件和网站被破坏。老实说,在我研究这个问题之前,我也指责PDF 因此,我正在尝试为我的用户解决这个问题。
我考虑过提供一个“下载PDF”链接(将
内容配置
标题设置为附件
,而不是内联
),但我的公司根本不喜欢这个解决方案,因为我们真的希望这些PDF文件显示在浏览器中
还有其他人经历过这个问题吗?
有哪些可能的解决方案或变通办法?
我真的希望有一个对最终用户无缝的解决方案,因为我不能依靠他们知道如何更改Adobe Reader设置或自动安装更新
这是可怕的灰色屏幕:编辑:屏幕截图已从文件服务器中删除!对不起
该图像是一个浏览器窗口,带有常规工具栏,但背景为纯灰色,没有任何用户界面 背景信息:
虽然我认为以下信息与我的问题无关,但我会将其包括在内以供参考:
这是一个ASP.NET MVC应用程序,有jQuery可用。
PDF文件的链接具有
target=\u blank
,因此它将在新窗口中打开。PDF文件是动态生成的,所有的内容标题都被适当地设置。 URL不包括
.pdf
扩展名,但我们使用有效的.pdf
文件名和内联设置设置内容配置
标题
编辑:以下是我用来提供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
):
使用System.Net.Mime;
使用System.Web.Mvc;
///
///返回正确的响应标题和PDF文件的“内容处置”,
///并允许您指定文件名以及是否由浏览器下载。
///
公共类PdfResult:FileContentResult
{
public ContentDisposition{get;private set;}
///
///返回PDF文件结果。
///
///PDF文件的数据
///确定文件应显示在浏览器中还是作为文件下载
///下载或保存文件时将显示的文件名。
///要格式化为文件名的参数列表。
///
[JetBrains.Annotations.StringFormatMethod(“文件名”)]
公共PdfResult(字节[]PdfileContent,bool下载,字符串文件名,参数对象[]文件名args)
:base(pdfFileContents,“application/pdf”)
{
//格式化文件名:
if(filenameArgs!=null&&filenameArgs.Length>0)
{
filename=string.Format(filename,filenameArgs);
}
//将文件名添加到内容处置中
ContentDisposition=新的ContentDisposition
{
内联=!下载,
FileName=FileName,
大小=PdfileContents.Length,
};
}
受保护的重写无效写文件(System.Web.HttpResponseBase响应)
{
//将文件名添加到内容处置中
AddHeader(“ContentDisposition”,ContentDisposition.ToString());
base.WriteFile(响应);
}
}
Hm,是否可以简单地执行以下操作:
用户第一次使用Javascript打开pdf时,您会弹出一个弹出窗口,基本上会显示“如果您看不到您的文档,请单击此处”。将“HERE”设置为一个大按钮,向用户解释问题所在。还可以制作另一个按钮“一切正常”。如果用户单击此按钮,您会记住它,因此将来不会显示它
我试着实际一点。对于我来说,为一小部分AdobeReader版本“正确”地解决这类问题花费了大量精力,这听起来并不是很有成效。在MVC1首次发布时,我遇到了这个问题。请参阅有关缓存控制标头的信息 我没有确切的解决方案,但我会将我的经验发布在这里,以防它们对其他人有所帮助
根据我的测试,灰色屏幕仅在速度较慢的机器上触发[1]。到目前为止,我还无法在较新的硬件上重新创建它[2]。我所有的测试都是在IE8和AdobeReader10.1.2中进行的。对于我的测试,我关闭了SSL并删除了所有可能禁用缓存的头文件
要重新创建灰色屏幕,我遵循以下步骤:
1) 导航到链接到PDF的页面
2) 在新窗口或选项卡中打开PDF(通过上下文菜单或target=“\u blank”)
3) 在我的测试中,此PDF将毫无错误地打开(但我已收到用户报告,表明第一次加载PDF时失败)
4) 关闭新打开的窗口或选项卡
5) 在新窗口或选项卡中(再次)打开PDF
6) 此PDF不会打开,而是只显示第一个用户(所有子用户)提到的“灰色屏幕”
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);
}
}
<html>
<head>...</head>
<body>
<object data="/pdf/sample.pdf" type="application/pdf" height="100%" width="100%"></object>
</body>
</html>
<!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>