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

Discussion in 'ASP .Net' started by =?Utf-8?B?VGlnZ2Vy?=, Nov 10, 2004.

  1. 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
    =?Utf-8?B?VGlnZ2Vy?=, Nov 10, 2004
    #1
    1. Advertising

  2. =?Utf-8?B?VGlnZ2Vy?=

    mortb Guest

    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" <> wrote in message
    news:...
    > 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
    >
    >
    >
    >
    mortb, Nov 10, 2004
    #2
    1. Advertising

  3. 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
    >
    >
    >
    >
    =?Utf-8?B?SmVyZW15IERhdmlz?=, Nov 10, 2004
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. John Klucker

    implementing a Printer Friendly .aspx Page

    John Klucker, Aug 15, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    387
    John Timney \(Microsoft MVP\)
    Aug 15, 2003
  2. =?Utf-8?B?U2FuZHk=?=

    Create Printer Friendly Version

    =?Utf-8?B?U2FuZHk=?=, May 6, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    951
    =?Utf-8?B?U2FuZHk=?=
    May 6, 2005
  3. =?Utf-8?B?SmltIEg=?=

    Printer Friendly Page

    =?Utf-8?B?SmltIEg=?=, Jul 1, 2005, in forum: ASP .Net
    Replies:
    3
    Views:
    444
  4. Yog
    Replies:
    0
    Views:
    447
  5. tommy
    Replies:
    2
    Views:
    96
Loading...

Share This Page