IE不会在浏览器中显示生成的PDF
本文关键字:PDF 显示 浏览器 IE | 更新日期: 2023-09-27 18:05:01
我已经尝试了很多方法来让它工作,如果我使用
Response.AddHeader("Content-Disposition", string.Format("attachment; filename={0}", newFileInfo.Name));
代替
Response.AddHeader("Content-Disposition", string.Format("inline; filename={0}", newFileInfo.Name));
它工作,但我需要这显示在浏览器窗口正常工作。内联视图在Chrome中正常工作。我试过使用Response。BinaryWrite和Response。WriteFile和它没有区别
我用的是ie9。
下面是我的代码: Response.Clear();
Response.ClearHeaders();
Response.ClearContent();
Response.Buffer = true;
Response.ContentType = "application/pdf";
Response.AddHeader("Pragma", "public");
Response.AddHeader("expires", "0");
Response.AddHeader("Cache-Control", "no-cache");
Response.Cache.SetCacheability(HttpCacheability.NoCache);
string filePath = Request["file"];
string signatureFile = Request["SignatureImage"];
double xPos = Convert.ToDouble(Request["X-Pos"]);
double yPos = Convert.ToDouble(Request["Y-Pos"]);
double scale = Convert.ToDouble(Request["Scale"]);
if (!string.IsNullOrEmpty(filePath))
{
try
{
string newFile = PDFTools.SignPDF(filePath, signatureFile, xPos, yPos, scale, tempDirectory);
var newFileInfo = new FileInfo(newFile);
Response.AddHeader("Content-Disposition", string.Format("inline; filename={0}", newFileInfo.Name));
Response.AddHeader("content-length", newFileInfo.Length.ToString());
Response.TransmitFile(newFile);
Response.Flush();
Response.Close();
}
catch (Exception ex)
{
Debug.WriteLine("Error: " + ex.Message);
Debug.WriteLine("at " + ex.StackTrace);
}
finally
{
Response.End();
}
}
谢谢你的时间!
Chrome有内置的PDF查看器,但Internet Explorer没有。您是否安装了外部PDF查看器(即adobeacrobat或adobereader)并配置为web视图?
抱歉,没有代表,不能发表评论