SitePoint Sponsor

User Tag List

Results 1 to 12 of 12
  1. #1
    SitePoint Enthusiast
    Join Date
    Oct 2007
    Location
    Texas
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Printer-Friendly Pages

    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.

  2. #2
    SitePoint Evangelist
    Join Date
    Feb 2006
    Location
    Worcs. UK
    Posts
    404
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

  3. #3
    SitePoint Enthusiast
    Join Date
    Oct 2007
    Location
    Texas
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks
    Web design is cool. Roll with it.

  4. #4
    SitePoint Guru silver trophy Luke Redpath's Avatar
    Join Date
    Mar 2003
    Location
    London
    Posts
    794
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Could you not just use a printer stylesheet?

    http://www.alistapart.com/articles/goingtoprint/

  5. #5
    SitePoint Evangelist
    Join Date
    Feb 2006
    Location
    Worcs. UK
    Posts
    404
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Nice link Luke. I expects that a better way to go in this instance.

  6. #6
    SitePoint Guru
    Join Date
    Aug 2005
    Posts
    986
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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:

    Code:
    respond_to do |format|
      format.print { ... }
      format.html { ... }
    end
    Or is this a dirty hack?

  7. #7
    SitePoint Evangelist
    Join Date
    Feb 2006
    Location
    Worcs. UK
    Posts
    404
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    According to the information on the page Luke linked to, you can specify the CSS via the HTML header info:
    Code:
    <link rel="stylesheet" type="text/css" media="print" href="print.css" />
    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!

    Interesting

  8. #8
    SitePoint Guru silver trophy Luke Redpath's Avatar
    Join Date
    Mar 2003
    Location
    London
    Posts
    794
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.

  9. #9
    SitePoint Enthusiast
    Join Date
    Oct 2007
    Location
    Texas
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks Luke!
    Web design is cool. Roll with it.

  10. #10
    SitePoint Evangelist
    Join Date
    Feb 2006
    Location
    Worcs. UK
    Posts
    404
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Luke Redpath View Post
    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.
    Sorry, I wasn't trying to suggest that people should do it, but rather that it was interesting that you could.

  11. #11
    SitePoint Member
    Join Date
    Oct 2007
    Posts
    21
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Fenrir2 View Post
    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:

    Code:
    respond_to do |format|
      format.print { ... }
      format.html { ... }
    end
    Or is this a dirty hack?
    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

  12. #12
    SitePoint Enthusiast
    Join Date
    Oct 2007
    Location
    Texas
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks Mad, I will check that out.
    Web design is cool. Roll with it.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •