Friday, May 10, 2024
 Popular · Latest · Hot · Upcoming
149
rated 0 times [  154] [ 5]  / answers: 1 / hits: 15911  / 12 Years ago, thu, july 19, 2012, 12:00:00

I'm wondering if there was any library or gem available in Rails for printing the contents of a web page, as in literally on to paper via a printer. I was also wondering if there was any way you can specify that only a specific part of the page (e.g. a div or something) would be printed? Any pointers, advice, or links to tutorials would be appreciated!



EDIT



so I've made a stab at creating a stylesheet which will create a print friendly view, let's call it print.css:



div.transpose-keys, div#editSong, div#navigation, div#debug{
display: none;
}


And I was wondering if there was any way I could apply it only when my application fires the print action? So that when the following is link is clicked
the application applies the css above before it prints? Here's the link in my embedded ruby html:



<%= link_to PRINT, '#', onclick: printpage() %>


And finally my javascript calling the print function:



function printpage()
{
window.print()
}

More From » html

 Answers
40

If you add your print.css as follows



<link rel=stylesheet type=text/css media=print href=print.css>


and use browser print dialog, it should automatically format the page according to the style in print.css


[#84146] Wednesday, July 18, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
quinlanhenryf

Total Points: 743
Total Questions: 93
Total Answers: 118

Location: Australia
Member since Sat, May 27, 2023
1 Year ago
;