[英]IE browser does not display Title and File Name for PDF set using iTextSharp
[英]IE will not display generated PDF in browser
如果我使用,我已经尝试了很多事情来让它工作
Response.AddHeader("Content-Disposition", string.Format("attachment; filename={0}", newFileInfo.Name));
代替
Response.AddHeader("Content-Disposition", string.Format("inline; filename={0}", newFileInfo.Name));
它可以工作,但我需要在浏览器 window 中显示才能正常工作。 内联视图在 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();
}
}
谢谢你的时间!
Chrome 有一个内置的 PDF 查看器,但 Internet Explorer 没有。 您是否为 web 视图安装和配置了外部 PDF 查看器(即 Adobe Acrobat 或 Adobe Reader)?
对不起,没有代表,不能发表评论。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.