0

I am wondering how to open a new tab with the following bit of code. Using "Inline" instead of attachment will open the pdf in the current window. By using "attachment", a Save box opens and download the pdf. I don't want to do either. I want the pdf to open in a new tab or even a new window is fine. Is there anyway? Pdf is dynamically created and can't just use

        <a href="x" target="blank">pdf</a>.

Thanks alot.

        Response.ContentType = "application/pdf"
        Response.AddHeader("content-disposition", "attachment; filename=Table.pdf")
        Response.BinaryWrite(m_stream.ToArray())
        Response.End()
Laurence
  • 7,633
  • 21
  • 78
  • 129

1 Answers1

1

It sounds like you know how to get the PDF file to open in the window (using "inline"), but you just want that to be a different window than the one that's invoking this code. It sounds like you have a link that navigates to the PDF creation page, but does so in the current window, and instead of doing that, have it open in a new window, like so:

<a href="/makepdf" target="_blank">Link Name</a>  <-- note that "target" attribute

where /makepdf is a page that runs the code you show above, but using "inline".

Joshua Frank
  • 13,120
  • 11
  • 46
  • 95
  • can't use anchor tag Joshua. need to write the code in the code behind. Is there any way I can change my code above abit and make it open in a new tab/page? Thanks – Laurence Mar 13 '12 at 14:46
  • Have the anchor (or other control that opens a new tab) pass in the required fields via QueryStrings to your PDF generating page. You can manage the values for the QueryStrings from the code-behind (if necessary). – NoAlias Mar 13 '12 at 15:07
  • Let me back up a step and ask this: how *does* this PDF generation code get invoked? How does the user request the page containing the sample code that you show in your question? – Joshua Frank Mar 13 '12 at 15:16
  • Thanks guys, I actually give up the idea of doing this. In fact, the code was written by some1 else and my manager asked me to change that. I can't really change the existing code. I thought it would be easy like "blank, filename=x.pdf" where I know i can either use Inline or Attachment at the moment. Thanks and see ya guys around. – Laurence Mar 15 '12 at 15:25