Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Please help - how to create a Printer Friendly web page...

Reply
Thread Tools

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

 
 
=?Utf-8?B?VGlnZ2Vy?=
Guest
Posts: n/a
 
      11-10-2004
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




 
Reply With Quote
 
 
 
 
mortb
Guest
Posts: n/a
 
      11-10-2004
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>

"Tigger" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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
>
>
>
>



 
Reply With Quote
 
 
 
 
=?Utf-8?B?SmVyZW15IERhdmlz?=
Guest
Posts: n/a
 
      11-10-2004
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/

"Tigger" wrote:

> 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
>
>
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Create Printer Friendly Version =?Utf-8?B?U2FuZHk=?= ASP .Net 2 05-06-2005 03:33 PM
"Printer Friendly" button help requested -- simple question Burak ASP .Net Web Controls 0 05-21-2004 04:04 PM
Help displaying printer friendly DataGrid in new window. Ray ASP .Net 2 12-19-2003 06:49 PM
Help please: Creating a printer friendly page from a form tommy Javascript 2 10-10-2003 08:04 PM
Printer Friendly pat Microsoft Certification 1 09-17-2003 02:56 PM



Advertisments