# Howto - display PDF file in new window ?

**URL:** <https://discuss.rubyonrails.org/t/howto-display-pdf-file-in-new-window/4578>\
**Category:** rubyonrails-talk\
**Created:** [November 15, 2006, 6:24pm UTC](https://discuss.rubyonrails.org/t/howto-display-pdf-file-in-new-window/4578 "2006-11-15T18:24:15Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bill\_Walton](https://avatars.discourse-cdn.com/v4/letter/b/f07891/32.png) [@Bill\_Walton](https://discuss.rubyonrails.org/u/Bill_Walton)\
**Post date:** [November 15, 2006, 6:24pm UTC](https://discuss.rubyonrails.org/t/howto-display-pdf-file-in-new-window/4578/1 "2006-11-15T18:24:15Z")

</div>

My app is creating a PDF in my app’s public directory. When the visitor clicks a button, I need to be able to display the file in a new window. I cannot figure out how to do it. Any help is greatly appreciated.

Thanks,

Bill

---

<div class="post-metadata">

**Author:** ![Jason\_Roelofs](https://avatars.discourse-cdn.com/v4/letter/j/e274bd/32.png) [@Jason\_Roelofs](https://discuss.rubyonrails.org/u/Jason_Roelofs)\
**Post date:** [November 15, 2006, 6:42pm UTC](https://discuss.rubyonrails.org/t/howto-display-pdf-file-in-new-window/4578/2 "2006-11-15T18:42:47Z")

</div>

If it’s a link, just add target=“\_blank” to the a tag. If it’s Javascript, there’s window.open(url, options\*) IIRC.

Jason

---

<div class="post-metadata">

**Author:** ![Bill\_Walton](https://avatars.discourse-cdn.com/v4/letter/b/f07891/32.png) [@Bill\_Walton](https://discuss.rubyonrails.org/u/Bill_Walton)\
**Post date:** [November 15, 2006, 7:52pm UTC](https://discuss.rubyonrails.org/t/howto-display-pdf-file-in-new-window/4578/3 "2006-11-15T19:52:48Z")

</div>

Guest wrote:

> Do you define the Content-Type of your page ?

No. Do I need to? This is the first time I've tried to display anything other than HTML from a Rails app. I'm feeling really lost.

Thanks, Bill

---

<div class="post-metadata">

**Author:** ![Bill\_Walton](https://avatars.discourse-cdn.com/v4/letter/b/f07891/32.png) [@Bill\_Walton](https://discuss.rubyonrails.org/u/Bill_Walton)\
**Post date:** [November 16, 2006, 12:07am UTC](https://discuss.rubyonrails.org/t/howto-display-pdf-file-in-new-window/4578/4 "2006-11-16T00:07:33Z")

</div>

Wes Gamble wrote:

> Here's an example of some code in a view to set up a link that will open up a new window to receive a PDF:

\<snip\>

> Hope this helps.

That was a huge help. Thank you, Wes!

> Let me know if you need more info.

Well... since you asked 😉 I really need to (visually) use a button rather than a link. The problem is that button\_to uses POST and so the :popup option doesn't work. Any suggestions?

Thanks again, Bill

---

<div class="post-metadata">

**Author:** ![Rizwan\_Reza](https://avatars.discourse-cdn.com/v4/letter/r/3d9bf3/32.png) [@Rizwan\_Reza](https://discuss.rubyonrails.org/u/Rizwan_Reza)\
**Post date:** [November 16, 2006, 8:42am UTC](https://discuss.rubyonrails.org/t/howto-display-pdf-file-in-new-window/4578/5 "2006-11-16T08:42:03Z")

</div>

There is no option to that. One possibility is to make a custom button.
