从动态网址下载动态生成的pdf,动态网址在vb.net中的adobe viewer中的webbrowser控件中查看 [英] Download dynamic generated pdf from dynamic url which is being viewed in webbrowser control in adobe viewer in vb.net

查看:78
本文介绍了从动态网址下载动态生成的pdf,动态网址在vb.net中的adobe viewer中的webbrowser控件中查看的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在vb.net中开发一个Windows应用程序,其中我有一个网址,首先要求我登录网站,然后显示一个视图pdf链接。当我点击它再次点击它重定向到另一个页面而不是要求下载pdf它在我的Web浏览器控件中打开它。现在我想在我指定的路径上保存打开的pdf。我搜索了很多,但没有找到相同的解决方案。我甚至找到了一些相关的帖子,但没有一个有我的答案。这里我的pdf网址不包含任何文件名,如'.pdf'。 Url包含一些令牌值。要打开此网址,需要在网站上登录。我试图下载pdf文件很多天。请帮助我。

解决方案

浏览器的行为基于响应标头中设置的响应类型。



这称为MIME类型,每种类型的文件都有一个。



如果将响应类型设置为 application / pdf 然后它会指示浏览器将文件视为pdf文件。



您还可以使用以下命令设置文件名:



  .Response.AddHeader(  Content-Disposition  attachment; filename = + file.Name); 





不幸的是,服务器无法控制浏览器的决定方式处理该文件类型。如果你正在使用带有PDF查看器的浏览器加入。浏览器响应可能是启动查看器而不是简单地下载文件。



但是默认的Adobe PDF视图应该可以保存文件。


 私有 声明 功能 URLDownloadToFile  Lib     urlmon 别名   URLDownloadToFileA _ 
ByVal pCaller As ByVal szURL 作为 字符串 ByVal szFileName A s 字符串 ByVal dwReserved As ,_
ByVal lpfnCB As 作为







使用下载代码:



 URLDownloadToFile(0&,strURL,strPath,0&,0&)

MsgBox( 下载完成 - 下载& strURL& to& strPath的)


I am developing a windows application in vb.net in which i have a url which first ask me to login on the website and then display a view pdf link. As i make it click it again redirect to another page where instead of asking for download pdf it opens it in my web browser control. Now i want to save that opened pdf on my specified path. I have googled a lot but didn't find any solution for the same. I even found some related posts but none of them have my answer. Here my pdf url doesnt contains any file name like '.pdf'. Url contains some token values. To open this url it requires login on the website. I am trying to download pdf file for many days. Please help me.

解决方案

The behaviour of the browser is based on the response type set in the response header.

This is called the MIME type and each type of file has one.

If you set the response type to application/pdf then it will instruct the browser to treat the file as a pdf file.

You can also set the file name using:

this.Response.AddHeader("Content-Disposition", "attachment; filename=" + file.Name);



Unfortunately, the server can't control how the browser decides to handle that file type. If you're using a browser with a PDF viewer add in. The browsers response could be to launch the viewer instead of simply downloading the file.

But the default Adobe PDF view should let you save the file.


Private Declare Function URLDownloadToFile Lib "urlmon" Alias "URLDownloadToFileA" _
   (ByVal pCaller As Long, ByVal szURL As String, ByVal szFileName As String, ByVal dwReserved As Long, _
   ByVal lpfnCB As Long) As Long




Use in your downloading code :

URLDownloadToFile(0&, strURL, strPath, 0&, 0&)

       MsgBox("Download finished - downloaded " & strURL & " to " & strPath)


这篇关于从动态网址下载动态生成的pdf,动态网址在vb.net中的adobe viewer中的webbrowser控件中查看的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆