# How to print a page using RJS

**URL:** <https://www.ruby-forum.com/t/how-to-print-a-page-using-rjs/169488>\
**Category:** Rails\
**Created:** [June 4, 2009, 11:41am UTC](https://www.ruby-forum.com/t/how-to-print-a-page-using-rjs/169488 "2009-06-04T11:41:01Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![manisha](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/6f9a4e/32.png) [@manisha](https://www.ruby-forum.com/u/manisha)\
**Post date:** [June 4, 2009, 11:41am UTC](https://www.ruby-forum.com/t/how-to-print-a-page-using-rjs/169488/1 "2009-06-04T11:41:01Z")

</div>

Hello everyone,

I am trying to add an option to print my view, i.e the display webpage  
in my Rails application.At present I am using HTML DOM for that but I  
want to do that in ruby.Following some online tutorials, I am trying to  
use rjs for that. the codes are some thing like this

# view.rhtml

\<%=link\_to\_remote (“Print Page”, :url =\> {:action =\> :print})%\>

# doc.rjs

page.hide ‘header’  
page.hide ‘header2’

page.\<\<‘javascript:window.open();’

page.show ‘header’  
page.show ‘header2’

Can anyone give some idea as to why this is not working?I have very less  
knowledge in this.Is there any other way to do the same?

---

<div class="post-metadata">

**Author:** ![manisha](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/6f9a4e/32.png) [@manisha](https://www.ruby-forum.com/u/manisha)\
**Post date:** [June 4, 2009, 12:21pm UTC](https://www.ruby-forum.com/t/how-to-print-a-page-using-rjs/169488/2 "2009-06-04T12:21:38Z")

</div>

Hi, Manisha T…

You can solve this problem by creating special css for printer,

\<%= stylesheet\_link\_tag “print\_style”, :media =\> “print” %\>

and in print\_style.css

#header{  
display:none;  
}  
and so on…

On Jun 4, 1:41 pm, Manisha T. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![manisha](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/6f9a4e/32.png) [@manisha](https://www.ruby-forum.com/u/manisha)\
**Post date:** [June 4, 2009, 2:30pm UTC](https://www.ruby-forum.com/t/how-to-print-a-page-using-rjs/169488/3 "2009-06-04T14:30:57Z")

</div>

Ok but in that case , I think we will not be using rjs file. right?  
Can you just explain a bit more please.

Rakoth wrote:

> Hi, Manisha T…
> 
> You can solve this problem by creating special css for printer,
> 
> \<%= stylesheet\_link\_tag “print\_style”, :media =\> “print” %\>
> 
> and in print\_style.css
> 
> #header{  
> display:none;  
> }  
> and so on…
> 
> On Jun 4, 1:41ï¿½pm, Manisha T. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![manisha](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/6f9a4e/32.png) [@manisha](https://www.ruby-forum.com/u/manisha)\
**Post date:** [June 4, 2009, 3:28pm UTC](https://www.ruby-forum.com/t/how-to-print-a-page-using-rjs/169488/4 "2009-06-04T15:28:19Z")

</div>

Yes, in this case you just add css tag to page that you want to print.  
This css will be used when you run print command in your browser,  
becouse parameter :media set to “print”.  
And you can specify look of a page when printed using the appropriate  
styles, for exalple to hide  
element with id=“header” or with class=“navigation” use

#header, .navigation{  
display:none;  
}

Try to find more information on this topic using google query “css  
media print”

forgive me my english, I`m using google translate.

On Jun 4, 4:30 pm, Manisha T. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
