stream a pdf to a .net webbrowser object on a winform

感情迁移 提交于 2020-01-16 09:11:11

问题


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

回答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.




回答2:


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.



来源:https://stackoverflow.com/questions/1610225/stream-a-pdf-to-a-net-webbrowser-object-on-a-winform

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!