本文介绍了流的PDF为.NET WebBrowser对象上一个WinForm的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个,我想用它来显示PDF格式的winform一个WebBrowser对象。PDF格式驻留在FTP服务器上。我已经能够通过下载来显示PDF格式磁盘和指向WebBrowser对象给它(导航),但我想流出于安全的原因。有没有人能流的PDF到位于一个.net的winform一个网页浏览器?

 昏暗URI的String =主机和功放; targetFilename
    昏暗的FTP作为System.Net.FtpWebRequest = CTYPE(FtpWebRequest.Create(URI)的FtpWebRequest)

    ftp.Credentials =新System.Net.NetworkCredential(用户名,密码)
    ftp.KeepAlive =假
    ftp.UseBinary = TRUE
    ftp.Method = System.Net.WebRequestMethods.Ftp.DownloadFile

    使用webResp作为System.Net.FtpWebResponse = DirectCast(ftp.GetResponse(),System.Net.FtpWebResponse)
        使用respStream作为物流= webResp.GetResponseStream
            如果GetFileExtension(targetFilename)=PDF然后
                WebBrowser1.DocumentStream = respStream
                Application.DoEvents()
            结束如果

            respStream.Close()
        结束使用
    结束使用
 

解决方案

既然你已经使用WebBrowser控件;为什么不把它指向本地HTML文件,其中包括一个嵌入标记:

 <嵌入SRC =FTP://ftpserver/yourpdf.pdf/>
 

我没有测试过,但PDF应控制的范围内送达。

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 itto the disk and pointing the webbrowser object to it (navigate), but I want to streamit 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
解决方案

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.

这篇关于流的PDF为.NET WebBrowser对象上一个WinForm的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 04:39