b310 has asked for the wisdom of the Perl Monks concerning the following question:

Hello:

I have a Perl script where a user receives a page full of results. I would like to have a link on the page for a "printer friendly" page. Is it possible to accomplish this? If so, can someone point me in the right direction?

Thank you in advance for any help.

Replies are listed 'Best First'.
Re: Printer Friendly Pages
by b10m (Vicar) on May 17, 2004 at 20:23 UTC

    This is where stylesheets come in really handy. If user requests the "printer friendly" page, don't use stylesheets, if not, do use stylesheets :-)

    It's kinda hard to be more specific, for I have no clue what your script does, nor what the output looks like and how it's generated...

    HTH

    --
    b10m

    All code is usually tested, but rarely trusted.

      Actually in both cases you should use CSS. You can either serve one stylesheet with any directives specifically for printing set off using @media print { ... }, or use multiple <link> elements with the apropriate media attribute. See Media Types in the CSS spec, or Designing With Web Standards (aka the hideous orange Zeldman book).

      Not that it has anything to do with perl . . .

      Hi:

      I have a form where the user enters a bunch of data. The data is passed to a script where it is processed via lots of calculations. The script then displays a page with the results of the calculations.

      I would like the user to have an option to click on a link or button that can show them a page where images, colors, etc. are all eliminated.

      I'm not quite sure how much more I can add about what my script does.

      Thanks for your reply.
Re: Printer Friendly Pages
by tilly (Archbishop) on May 17, 2004 at 23:28 UTC
    One strategy.

    Use a templating module like Template::Toolkit along with some kind of make utility (like ttree, that comes with Template::Toolkit).

    In the make process, create 2 versions of every page. One of which has images, colours, etc. One of which does not.

    Alternately you could use CSS as previously suggested.

Re: Printer Friendly Pages
by tachyon (Chancellor) on May 18, 2004 at 03:55 UTC

    The way I do it is like this. My output is templated. The template looks like:

    <html> <head> <link rel="stylesheet" type="text/css" href="./docs.css"> <script type="text/javascript" language="JavaScript"> <!-- Begin function PrinterFriendlyPage() { var HTML; eval("HTML = document.getElementById('contentstart').innerHTML"); if ( ! HTML || ! window.print ) { alert('Your Browser does not support printing.'); } else { var pfw=window.open("","","toolbar=no,location=no,directories= +no,menubar=yes,scrollbars=yes,width=750,height=600,left=100,top=25"); pfw.document.open(); pfw.document.write('<p>\n'); pfw.document.write('<'+'script>function PrintPage () { window. +print() }<'+'/script>\n'); pfw.document.write('<p><a href="javascript:PrintPage()">Print +This Page</a>\n</p>'); pfw.document.write(HTML); pfw.document.write('<p>'); pfw.document.close(); pfw.focus(); } } // End --> </script> </head> <body> <h1>This is where the site template HTML goes</h1> <p><a href="javascript:PrinterFriendlyPage()">Printer Friendly Version +</a> <div id="contentstart"> <p>Anything between these div tags will show in printer friendly windo +w. </div> <h1>More site template HTML goes here</h1> </body> </html>

    Just save this as HTML and open it in a browser. Anything between the contentstart div tags will get extracted by the js into the pf window which the script pops up, complete with click here to print link. You can also document.write a (new) style sheet link in as desired.

    Note in practice I call the PrinterFriendlyPage() function PrinterFriendlyPageNNNN where NNNN is different for every page. The reason is that the history object will remember that the link to PrinterFriendlyPage() has been visited so these links will all change to visited as soon as a user prints a single page. Same for the PrintPage() function that gets written in the JS. Anyway that is one way to do it neatly and rather simply.

    cheers

    tachyon

      Good Morning,

      Thanks for the information. I'll give it a try and see what happens.

      Thank you for the help.