【发布时间】:2013-05-09 18:17:58
【问题描述】:
我正在从 webbrowser 控件导航到这样的 url; http://www.who.int/cancer/modules/Team%20building.pdf
它显示在网络浏览器控件中。我想要做的是把这个pdf文件下载到电脑上。但是我尝试了很多方法;
Dim filepath As String
filepath = "D:\temp1.pdf"
Dim client As WebClient = New WebClient()
client.DownloadFileCompleted += new AsyncCompletedEventHandler(client_DownloadFileCompleted);
client.DownloadFileAsync(WebBrowserEx1.Url, filepath)
这个下载了一个pdf,但文件中没有任何内容。
也试过
objWebClient.DownloadFile()
什么都没有改变。
我试图显示一个保存或打印对话框;
WebBrowserEx1.ShowSaveAsDialog()
WebBrowserEx1.ShowPrintDialog()
但他们没有显示任何对话框。也许最后一个是因为它没有等待将pdf完全加载到webbrowser中。
当我尝试 html 文件时,下载没有问题,但是在这个 .pdf 文件中,我想我没有设法等待文件以 pdf 格式加载到浏览器中。这个函数;
Private Sub WaitForPageLoad(ByVal adimno As String)
If adimno = "1" Then
AddHandler WebBrowserEx1.DocumentCompleted, New WebBrowserDocumentCompletedEventHandler(AddressOf PageWaiter)
While Not pageReady
Application.DoEvents()
End While
pageReady = False
End If
End Sub
Private Sub PageWaiter(ByVal sender As Object, ByVal e As WebBrowserDocumentCompletedEventArgs)
If WebBrowserEx1.ReadyState = WebBrowserReadyState.Complete Then
pageReady = True
RemoveHandler WebBrowserEx1.DocumentCompleted, New WebBrowserDocumentCompletedEventHandler(AddressOf PageWaiter)
End If
End Sub
不适用于这种情况。我的意思是它进入无限循环。
所以任何人都知道如何等待它加载 pdf 然后保存到计算机中。
【问题讨论】: