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


In reply to Re: Printer Friendly Pages by tachyon
in thread Printer Friendly Pages by b310

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.