Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I put a print link/button on my project page to printout an infomation?

I am using Rails for my application(student register) and i need a print link/button to print out some student's information. Please what do I do?

like image 325
Eseosa Oshodin Avatar asked Jul 22 '11 12:07

Eseosa Oshodin


3 Answers

You can use this tag to make a print link.

<%= link_to 'print', 'your_link_here', :onclick => 'window.print();return false;'%>

Now, if you want to print a specific section, you can use media types of css

/*This css will only works when you print*/
@media print {
  body {
    background: #FFF;
 }
}
like image 123
Gustavo Bacelar Avatar answered Sep 22 '22 23:09

Gustavo Bacelar


I'm not sure if i misunderstand something here because this seems more like a javascript question then a rails one to me: But here is how you make a print link:

<a href="#" onclick="window.print();return false;">print me</a> 

Note: the return false is critical, otherwise the app will hung up.

You could also make a special print page with only the desired information and have window.print in the onload event like this:

<body onload="window.print();">
like image 36
f.anderzon Avatar answered Sep 26 '22 23:09

f.anderzon


Include this in where you want to add the print button

function printPage() {
    window.print()
}

After that, give a link or button

<%= link_to "print", "#", onclick: "printPage()" %>
like image 28
Gajanan Ghuge Avatar answered Sep 25 '22 23:09

Gajanan Ghuge