保存从 Web 浏览器控件动态生成的 PDF
我的 Windows 窗体中有一个 Web 浏览器控件。我正在尝试自动化网站中的某些流程。在此过程中,发票 pdf 已动态生成并显示在 Web 浏览器控件中。我需要将该 pdf 保存在本地。请注意:没有直接下载 pdf 的链接。这几天我用谷歌搜索了很多,但还没有找到任何解决方案。
有人可以帮我解决这个问题吗?
谢谢。
I have a web browser control in my windows form. I am trying to automate some process in a website. During this process, the invoice pdf has been generated dynamically and shown in the web browser control. I need to save that pdf locally. Please note: there is no direct link to download the pdf. I googled a lot past couple of days and haven't found any solution yet.
Can someone help me on this?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我建议处理
WebBrowser.Navigating
事件。此事件的参数之一是WebBrowserNavigatingEventArgs< /code>
它有一个名为
网址
。如果幸运的话,该属性将以.pdf
结尾。如果您不幸运,您可能必须执行手动HEAD
请求并检查返回的 MIME 类型以查看其是否为 PDF。您可以尝试的另一件事是处理
WebBrowser.FileDownload
事件,但我不确定在浏览器中查看的 PDF 是否会引发该事件。如果您对正在运行的计算机拥有绝对控制权,我建议您禁用浏览器中的 PDF 查看功能,而只处理此事件。I would recommend handling the
WebBrowser.Navigating
event. One of the parameters of this event isWebBrowserNavigatingEventArgs
which has a property calledUrl
. If you're lucky, that property will end in.pdf
. If you're not lucky you might have to perform a manualHEAD
request and inspect the returned MIME-type to see if its a PDF.Another thing that you could try is handling the
WebBrowser.FileDownload
event but I'm not sure if it will be raised for PDFs viewed in-browser. If you have absolute control over the machine this is running on I would recommend disabling viewing of PDFs in the browser and just handle this event instead.