0

I have a webbrowser object on a winform that I would like to use to display a pdf. The pdf resides on a ftp server. I have been able to show the pdf by downloading it to the disk and pointing the webbrowser object to it (navigate), but I want to stream it for security reasons. Has anyone been able to stream a pdf to a webbrowser that is located on a .Net winform?

    Dim URI As String = host & targetFilename
    Dim ftp As System.Net.FtpWebRequest = CType(FtpWebRequest.Create(URI), FtpWebRequest)

    ftp.Credentials = New System.Net.NetworkCredential(userName, passWord)
    ftp.KeepAlive = False
    ftp.UseBinary = True
    ftp.Method = System.Net.WebRequestMethods.Ftp.DownloadFile

    Using webResp As System.Net.FtpWebResponse = DirectCast(ftp.GetResponse(), System.Net.FtpWebResponse)
        Using respStream As Stream = webResp.GetResponseStream
            If GetFileExtension(targetFilename) = "PDF" Then
                WebBrowser1.DocumentStream = respStream
                Application.DoEvents()
            End If

            respStream.Close()
        End Using
    End Using
sparkkkey
  • 158
  • 1
  • 10

2 Answers2

1

I would recommend using a PDF Viewer Control rather than a web browser control, as a web browser control will require that the client have a PDF Viewer installed.

This will also allow you to stream a document to it.

Russ Bradberry
  • 10,705
  • 17
  • 69
  • 85
  • The boss doesn't like the idea of having to distribute more files to get this work. I will use a PDF Viewer Control if I can't get the webbrowser to work. Will the PDF Viewer Control work well with streamed data? – sparkkkey Oct 22 '09 at 22:18
  • Russ, I agree with you that the PDF Viewer Control would be the most "correct" way to do it. I just don't want to give up on the webbrowser yet. – sparkkkey Oct 22 '09 at 22:25
  • The PDF Viewer control will work with streamed data. It is also open source so there will only be the need of one other file to distribute. This is a much better alternative than getting calls from angry people who don't have Acrobat installed because their pdf viewer is showing a big red X – Russ Bradberry Oct 22 '09 at 22:33
  • I agree Russ. Thanks for helping me with this problem! I will have to put this project on hold until I can distribute the needed dependency. – sparkkkey Oct 23 '09 at 15:52
1

Since you're already using the WebBrowser control; why not have it point to a local html file that includes an embed tag:

<embed src="ftp://ftpserver/yourpdf.pdf" />

I haven't tested it, but the pdf should be served within the context of the control.

gn22
  • 2,076
  • 12
  • 15
  • 1
    you can always pass credentials in plaintext, but it is not safe. the unsafe way to do this would be: ftp://user:password@ftpserver/yourpdf.pdf – Russ Bradberry Oct 22 '09 at 22:37
  • Thanks for the idea Gurdas! The security concerns (passing credentials) prevent me from implementing this soln. – sparkkkey Oct 23 '09 at 15:50