-3

Can anyone please tell me how could I stream a pdf to a new tab browser? I just have the pdf stream on memory and when I click over the link I want to show the PDF in a new tab or window browser. How can I accomplish this? Thanks in advance!

I have this link:

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

In the code above 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;      
}

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

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

henser
  • 3,307
  • 2
  • 36
  • 47
user2315877
  • 103
  • 1
  • 2
  • 8
  • Adding a new question, exactly like another one, isn't really the right approach. Edit the other one if it didn't have enough substance to it. Now, the primary question here is that you want to stream a PDF to the user in memory? Is there a **compelling reason** you don't just set the `href` to a real path so that the browser can handle ***everything*** for you? – Mike Perrenoud Apr 24 '13 at 15:18
  • Sorry just made a mistake...the fact is, I get the pdf stream from my azure, I can not show the whole url, has to manage showing the stream. Hope u understand. – user2315877 Apr 24 '13 at 15:30

1 Answers1

1
Response.Clear();

Response.ClearHeaders();

Response.ClearContent();

Response.AddHeader("Content-Disposition", "attachment; filename=" + file.Name);

Response.AddHeader("Content-Length", file.Length.ToString());

Response.ContentType = "application/pdf";

Response.Flush();

Response.TransmitFile(file.FullName);

Response.End();
Oscar
  • 13,594
  • 8
  • 47
  • 75