在浏览器中流式传输 Pdf 时如何设置文件名?
不确定如何确切地表达这个问题......所以欢迎编辑! 无论如何……就这样吧。
我目前使用 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。 无论如何我可以设置这个吗? 如果是这样,怎么办?
任何帮助,将不胜感激。
Not sure exactly how to word this question ... so edits are welcomed! Anyway ... here goes.
I am currently use Crystal Reports to generated Pdfs and just stream the output to the user. My code looks like the following:
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();
After this code runs it streams the Pdf to the browser opening up Acrobat Reader. Works great!
My problem is when the user tries to save the file it defaults to the actual file name ... in this case it defaults to CrystalReportPage.pdf. Is there anyway I can set this? If so, how?
Any help would be appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
通常,通过内容处置标头 - 即
因此只需使用 Headers.Add 或 AddHeader 或其他任何内容:
response.Headers.Add("Content-Disposition", "inline; filename=foo.pdf");
(内联是“在浏览器中显示”,附件是“另存为文件”)
Usually, via the content-disposition header - i.e.
So just use Headers.Add, or AddHeader, or whatever it is, with:
response.Headers.Add("Content-Disposition", "inline; filename=foo.pdf");
(inline is "show in browser", attachment is "save as a file")