Please help - how to create a Printer Friendly web page...

G

Guest

Dear Experts,
I've got a trouble problem that I need your help. The scenario is the
following:

1) I need to add a "Print" button to my web page;
2) by clicking this button, the web page should be able to print out a
well-formatted web page (printer friendly ). That means, I need to adjust the
printing margins (left, top, right, bottom) programmatically.

I really have no idea on how to achieve this but I know this is a very
typical scenario. Could you please give me some advices? Please help.

Thanks a lot.
Tigger
 
M

mortb

As long as the targetted browser is IE >= 5 you can use the onbeforeprint
and on afterprint events in javascript
(I found this out yeterday)
I wrote the code below to hide a print button and decrease the width when
the document is printed
Hope this helps,
mortb

<head>
<script language="javascript">
var originalWidth;
function window.onbeforeprint()
{
originalWidth = document.getElementById('_tblResult').style.width;
document.getElementById('_tblResult').style.width = '625px';
document.getElementById('_btnPrint').style.display = 'none';
}
function window.onafterprint()
{
document.getElementById('_tblResult').style.width = originalWidth;
document.getElementById('_btnPrint').style.display = 'inline';
}
</script>
</HEAD>
 
G

Guest

Use a media-specific print stylesheet.
For example, try slapping this in a file called print.css
@page { 0.75in; }
And putting this line in your HTML
<link rel="stylesheet" type="text/css" href="print.css" media="print">

At this point, you should be able to print from your browser normally. If
you need to initiate printing from a button, you should be able to do
something like this:
<input type="button" value="Print me!" onclick="window.print()">

This article might give you some ideas on other things you can do with this
techinque: http://www.alistapart.com/articles/goingtoprint/
And there's always the CSS reference: http://www.w3.org/TR/CSS21/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,016
Latest member
TatianaCha

Latest Threads

Top