I would like to be able to have my show methods display in a Printer-friendly format if I click a link to do so. Is there a plugin or easy way to accomplish this? Thanks.
| SitePoint Sponsor |
I would like to be able to have my show methods display in a Printer-friendly format if I click a link to do so. Is there a plugin or easy way to accomplish this? Thanks.
Web design is cool. Roll with it.



PDF is one way to go:
Rails PDF plug-in
or have a look at this article:
http://www.artima.com/rubycs/articles/pdf_writer.html
and here
http://ruby-pdf.rubyforge.org/pdf-writer/index.html
Thanks![]()
Web design is cool. Roll with it.
Could you not just use a printer stylesheet?
http://www.alistapart.com/articles/goingtoprint/



Nice link Luke. I expects that a better way to go in this instance.




A printer stylesheet is probably the way to go, but if you must show different html for printing you can add a content type and use something like this:
Or is this a dirty hack?Code:respond_to do |format| format.print { ... } format.html { ... } end



According to the information on the page Luke linked to, you can specify the CSS via the HTML header info:
Though of course catching it with respond_to at the server does offer possibility of serving the page in HTML unless the media request is for print, when a PDF will be rendered!Code:<link rel="stylesheet" type="text/css" media="print" href="print.css" />
Interesting![]()
If you want to serve up a PDF representation of a view, then there is no need to register a custom "print" mime/type; just use the PDF mimetype.
Thanks Luke!
Web design is cool. Roll with it.



There is a lot of debate over print stylesheet vs Separate layout vs PDF.
Using stylesheets is the PROPER way to do things (From a standards POV), as the File>Print feature works as expected. If you feel it necessary to use a "Print" link, use the document.print() javascript method.
If that isn't possible, a seperate layout is the next best option - for Rails 2.0 have a look at my blog post about aliasing formats.
Avoid PDF generation - it's too server intensive, requires a plug-in and is generally annoying to the end-user.
Hope that helps
Thanks Mad, I will check that out.
Web design is cool. Roll with it.
Bookmarks