内联文件名内容处置和注入动态文件名以保存操作的解决方案
本质上,我正在将 pdf 从内存传输到用户的浏览器。我希望系统用户能够在 adobe 中(在浏览器中)点击“保存”,并使用动态值预先填充文件名(例如客户的姓氏)。
到目前为止,我已经阅读了一些有关此问题的内容,似乎设置内联文件名的内容处置标头未正确实现。
我读到 adobe 从生成 pdf 的页面获取文件名。即,如果页面名称是 pdfviewer.aspx,则 pdf 文件名的预填充值是 pdfviewer.pdf。
我正在寻找解决方法。我最初的想法是创建一个 http 处理程序,它将生成并推出 pdf,并具有这样的 Web 配置:
<add verb="*" path="*.ashx" type="Logic.PDFHandler" />
这样,当我动态地将链接设置为“lastname.ashx”时,它应该运行 PDFHandler 中的代码,而url 类似于“...\lastname.ashx”。我似乎能够让它在概念验证中发挥作用(用简单的repsonse.write(“hello world”)替换pdf的生成),但我只是想知道是否有更好的解决方法?
注意:概念验证仅适用于 IE,我对此感到高兴,因为它是针对此 Intranet 应用程序的浏览器。
Essentially I am streaming a pdf from memory to the user's browser. I would like to allow the system user to be able to hit save in adobe (in browser) and have the filename pre-filled with a dynamic value (e.g. last name of the customer).
I've read a bit about this problem so far, it seems that content disposition header setting the inline filename isn't implemented correctly.
I have read that adobe takes the filename from the page that generates the pdf. I.e. if the page name is pdfviewer.aspx, then the pre-filled value of the pdf's filename is pdfviewer.pdf.
I am looking for a work around. My original idea was for a http handler which will generate and push out the pdf, and have the web config as such:
<add verb="*" path="*.ashx" type="Logic.PDFHandler" />
This way when I dynamically set the link to "lastname.ashx", it should run the code in PDFHandler, while the url will be somthing like "...\lastname.ashx". I seem to be able to get this to work in a proof of concept (substituting the generation of the pdf with a simple repsonse.write("hello world")), but I'm just wondering, if there are any better work arounds?
Note: The proof of concept only works in IE and I'm happy for it as it is the browser targeted for this intranet application.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
ASP.NET 路由可以让您将
/GeneratePDF/{id}/{lastname}.pdf
或其他内容路由到您的处理程序。ASP.NET routing would let you route
/GeneratePDF/{id}/{lastname}.pdf
or something to your handler.让浏览器要求您以给定名称保存 PDF 的方法如下:
The way to make the browser ask you to save the PDF with a given name is as follows: