流PDF浏览器? [英] Stream PDF to browser?

查看:110
本文介绍了流PDF浏览器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

谁能告诉我我怎么能流的PDF到一个新的选项卡浏览器?我只是在内存中的PDF格式的流,我想,当我点击了该链接,显示在新标签或窗口浏览器中的PDF文件。
我怎么能这样做呢?
谢谢!

Could anyone please tell me how could I stream a pdf to a new tab browser? I just have the pdf stream on memory and I want when I click over the link to show the PDF in a new tab or window browser. How could I do that? Thank!!!

我有此链接:

<a id="hrefPdf" runat="server" href="#" target="_blank"><asp:Literal ID="PdfName" runat="server"></asp:Literal></a>

在我的code后面我有这样的onload事件:

In my code behind I have this on the onload event:

                Stream pdf= getPdf
                if (pdf != null)
                {
                    SetLinkPDF(pdf);
                }

    private void SetLinkPDF(IFile pdf)
    {
        hrefPdf.href = "MyPDF to the Browser"
        PdfName.Text = pdf.PdfName;      
    }

好歹我必须处理流PDF(包含的IFile名称,流,元数据的PDF等)

Someway I have to process the stream pdf (IFile contains Name, Stream,Metadata, etc of the PDF)

我能做些什么来proccess这和我磨片点击一个新的浏览器显示流?

What can I do to proccess this and whe I click show the stream at a new browser?

我还有一个万阿英,蒋达清,不工作的OnClientClick =aspnetForm.target ='_空白; timbck2建议我。我有一个新窗口中打开该文件(图像或PDF),我能怎么办呢?不工作这一点。谢谢!

I have another probelm, is not working the OnClientClick="aspnetForm.target='_blank';" timbck2 suggested me. I have to open the file (image or pdf ) in a new window, what could I do? Is not working this. Thank!

Timbbck2我的ASP code是:

Timbbck2 my asp code is:

<asp:LinkButton runat="server" ID="LinkButtonFile" OnClick="LinkButtonFile_Click" OnClientClick="aspnetForm.target = '_blank';"></asp:LinkButton>

谢谢!

推荐答案

我已经从一个文件在磁盘上做到了这一点 - 从内存流发送数据不应该是太大的不同。需要提供的元数据的两块给浏览器,除了数据本身。首先,你需要提供的MIME类型的数据(在你的情况下,将应用程序/ PDF ),然后在一个内容字节(整数)的数据的大小-length头,然后发送数据本身。

I've done this from a file on disk - sending the data from a memory stream shouldn't be that much different. You need to supply two pieces of metadata to the browser, in addition to the data itself. First you need to supply the MIME type of the data (in your case it would be application/pdf), then the size of the data in bytes (integer) in a Content-Length header, then send the data itself.

因此​​,在总结(考虑到的意见和我的觉得的你问,你的标记应该是这样的:

So in summary (taking into account the comments and what I think you're asking, your markup would look like this:

<asp:LinkButton ID="whatever" runat="server" OnClick="lnkButton_Click" 
  OnClientClick="aspnetForm.target='_blank';">your link text</aspnet:LinkButton>

C#code您的code这些几行字后面应该做的伎俩(或多或少):

These few lines of C# code in your code behind should do the trick (more or less):

protected void lnkButton_Click(object sender, EventArgs e)
{
    Response.ClearContent();
    Response.ContentType = "application/pdf";
    Response.AddHeader("Content-Disposition", "inline; filename=" + docName);
    Response.AddHeader("Content-Length", docSize.ToString());
    Response.BinaryWrite((byte[])docStream);
    Response.End();
}

这篇关于流PDF浏览器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆