![](/img/trans.png)
[英]IE browser does not display Title and File Name for PDF set using iTextSharp
[英]How to set the name of the file when streaming a Pdf in a browser?
不确定如何说出这个问题...欢迎编辑! 无论如何......这里去了。
我目前使用Crystal Reports生成Pdfs并将输出流式传输给用户。 我的代码如下所示:
System.IO.MemoryStream stream = new System.IO.MemoryStream();
stream = (System.IO.MemoryStream)this.Report.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat);
this.Response.Clear();
this.Response.Buffer = true;
this.Response.ContentType = "application/pdf";
this.Response.BinaryWrite(stream.ToArray());
this.Response.End();
运行此代码后,它将Pdf流式传输到浏览器,打开Acrobat Reader。 效果很好!
我的问题是当用户尝试将文件保存为实际文件名时...在这种情况下,它默认为CrystalReportPage.pdf。 无论如何我可以设置这个吗? 如果是这样,怎么样?
任何帮助,将不胜感激。
通常,通过内容处置标题 - 即
Content-Disposition: inline; filename=foo.pdf
所以只需使用Headers.Add或AddHeader,或者其他任何东西,使用:
response.Headers.Add(“Content-Disposition”,“inline; filename = foo.pdf”);
(内联是“在浏览器中显示”,附件是“另存为文件”)
System.IO.MemoryStream stream = new System.IO.MemoryStream();
stream = (System.IO.MemoryStream)this.Report.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat);
this.Response.Clear();
this.Response.Buffer = true;
this.Response.ContentType = "application/pdf";
this.Response.AddHeader("Content-Disposition", "attachment; filename=\""+FILENAME+"\"");
this.Response.BinaryWrite(stream.ToArray());
this.Response.End();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.