如果我使用
,我已经尝试了许多工作来实现这一点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,它没有任何区别。
我正在使用Internet Explorer 9。
这是我的代码:
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();
}
}
谢谢你的时间!
答案 0 :(得分:2)
Chrome有一个内置的PDF查看器,但Internet Explorer没有。您是否为Web视图安装并配置了外部PDF查看器(即Adobe Acrobat或Adobe Reader)?
对不起,没有代表,也无法发表评论。