Programmatically save PDF displayed inside Win Form

Hello!
I am currious if it is possible to save a pdf that is being displayed in a web browser control or an adobe activex control inside my vb windows form. All I need it to do is pretty much save the pdf with the same name and location as it was opened, without any user intervention, so that I can stream it back into the database. I have seen alot of similar posts and I haven't really seen a solution to any of them.

Thanks in advanced
dpsavyAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
kblauConnect With a Mentor Commented:
You can drop a WebBrowser control on a page and use the following code.
Imports System.Threading
 
Public Class Form1
 
    Private Sub WebBrowser1_DocumentCompleted(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
        Dim u As String = e.Url.ToString()
        If (u.Substring(u.Length - 4, 4) = ".pdf") Then
 
            'new thread
            Dim ts As ThreadStart = New ThreadStart(AddressOf SaveFile)
            Dim t As Thread = New Thread(ts)
            t.Start()
 
 
        End If
    End Sub
 
    Private Sub SaveFile()
       
 
        Dim request As System.Net.WebRequest = System.Net.HttpWebRequest.Create(WebBrowser1.Url.ToString())
        Dim response As System.Net.HttpWebResponse = request.GetResponse()
        Dim stream As System.IO.Stream = response.GetResponseStream()
        ' Get the length of the content
        Dim length As Integer = response.ContentLength
        
        ' Create a temporary array for the content of the file.
        Dim bytes(length) As Byte
        ' Get all bytes of the content and advance the progress bar.
        For i As Integer = 0 To length - 1
            bytes(i) = stream.ReadByte()
 
 
            'Application.DoEvents()
        Next
        ' Write the content to the local file.
        Dim filename As String = "c:\" & GetFileName()
        Using output As IO.Stream = System.IO.File.Create(filename)
            output.Write(bytes, 0, bytes.Length)
        End Using
 
           
 
    End Sub
 
    Private Function GetFileName() As String
 
        Dim u As String = WebBrowser1.Url.ToString()
        Dim lastIdxOf As String = u.LastIndexOf("/")
        Return u.Substring(lastIdxOf + 1, u.Length - lastIdxOf - 1)
 
    End Function
 
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        WebBrowser1.Url = New Uri("http://www-128.ibm.com/developerworks/rational/library/content/03July/2500/2772/2772_uml.pdf")
    End Sub
End Class

Open in new window

0
 
Computer101Commented:
Forced accept.

Computer101
EE Admin
0
All Courses

From novice to tech pro — start learning today.