|
Rank: Member Groups: Member
Joined: 1/29/2015 Posts: 26
|
I am looking for a way to save a PDF that is displayed on a web page, either as an embedded iFrame or as a full page as displayed as a secondary dialog. I initially did the solution of intercepting the Save dialog such as: Private Sub WebView1_FileDialog(sender As Object, e As EO.WebBrowser.FileDialogEventArgs) Handles WebView1.FileDialog e.Continue(Path.Combine(Environ("TEMP"), "report.pdf")) e.Handled = True End Sub Private Sub WebView1_DownloadCompleted(sender As Object, e As EO.WebBrowser.DownloadEventArgs) Handles WebView1.DownloadCompleted AddDocument("Credit", "Report", Path.Combine(Environ("TEMP"), "report.pdf")) End Sub
However, this is not reliable. We have some stations that it works ok, but others will still prompt for the save as dialog and we can't find out what is wrong.
I am trying to find another way to save the PDF with our own button. Tried this: Using webClient = New WebClient() Dim bytes = webClient.DownloadData(WebView1.Url.ToString)
File.WriteAllBytes("d:\test\report.pdf", bytes) End Using But this won't work because the webClient is a different session than the WebView so it just dumps the home page instead of the PDF that is displayed. Is there anyway to dump the contents of the WebView to a file?
thanks
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,229
|
Hi,
Doing it through the download interface is the correct way to do it. Make sure you handle the WebView's ShouldForceDownload event because unless you force download the PDF, WebView will open it in the built-in PDF viewer.
Thanks!
|
|
Rank: Member Groups: Member
Joined: 1/29/2015 Posts: 26
|
The site we are working with has a PDF embedded within an iFrame. The user has to click the download icon within the PDF window, then our code saves the file instead of it popping up a Save as dialog. This mostly works, just a few installations still pop open the save as dialog instead. We don't know why.
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,229
|
I am not sure what else to tell you --- if you can reduce the app into a minimum (I recommend you modify based on our TabbedBrowser sample) that demonstrates the problem and provide us access to the system (such as through TeamViewer) that is having problem, we will be happy to investigate further.
|
|
Rank: Member Groups: Member
Joined: 1/29/2015 Posts: 26
|
Is there any way to do a direct download from a URL using the webview control? I would have to do this to keep the session in tact since it requires login.
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,229
|
Hi,
I am not sure exactly what you meant by "do a direct download from a URL". If your server requires a session cookie in order to serve the download, then the cookie must exist on the client side first. This is a requirement on your server side, it doesn't have much to do with the client side at all. If you just want a straight download, you can modify your server to skip the authentication part.
Thanks!
|
|
Rank: Member Groups: Member
Joined: 1/29/2015 Posts: 26
|
We don't have control over the server. We are hosting the site in our application. The user fills out a form then submits and the site returns a page with the PDF embedded on it. We are trying to make it so the user clicks one button to save the PDF back into our application. I can figure out the URL to get the PDF from the source but can't do a HTTP download with the webClient object because it will kick off another session with the server which isn't logged in. I would like to do a HTTP download to a file using the current WebView session somehow. Or somehow take the PDF that is displayed and save it as a file. Thanks
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,229
|
In that case you just have to figure out what the server wants from you and do whatever the server wants. Usually the server would need an authentication cookie, then you must provide that cookie. The "normal" way for providing that cookie is when you login, the server sends that cookie to you (in this case EO.WebBrowser), the browser engine will then send that cookie back to the server for further request thus proves to the server that it did receive permissions from the server earlier. You do not have to do the login part, but if the server wants a cookie from you in order to serve the download, then there would be no way around that (otherwise it would be a security hole for the server that needs to be fixed) and you must provide that cookie, this is true regardless which client side product/library you use. If you use EO.WebBrowser, then you can attach a cookie to a request by calling WebView.LoadRequest insted of LoadUrl.
|
|