printing my web pages

Posted on 2005-04-15
Last Modified: 2010-04-23
I created an online invoice (aspx) for the user to print out, but when I print out the information part of my invoice gets cut off (right side).  Is there a way in .net that all my information will get captured. ( I am using the print button on the browser)
Question by:genesisproject
    LVL 5

    Expert Comment

    No. runs on server side. It has no idea when printing occurs.

    However you can use a seperated style sheet used when printing occur. Use following syntax....
    <LINK rel="stylesheet" type"text/css"  href="youStyleSheetPrintFile.css" media="print">

    LVL 13

    Accepted Solution

    This is what I did, because I had a navigation menu on the left, and it was pushing my form off the printable area of the page.

    I added this to the html header section of my aspx page:

    <script Language="JavaScript">
                      function PrintThisPage()
                      var sOption="toolbar=no,location=no,directories=no,menubar=yes,";


    And this is the link on the navigation menu to get to the print page:
         <td><a href="javascript:PrintThisPage();"><IMG height="29" alt="Printer Friendly Version"  src="../images/template/printpreview.gif" width="158" border="0"></a></td>

    When a user clicks the print link, it will open the "Print.aspx" page via the function above.

    Now, here's the important part.  You need to put the tag <div id="contentstart"> </div> around the content on your original page that you want printed.  The sub will send the part of the webpage enclosed by the "div" tag over to the Print.aspx page.
    For example, I placed mine around the form elements like this:

    <div id="contentstart">
       <form id="Form1" method="post" runat="server">
            <asp:label id="lblTitle" style="Z-INDEX: 101; LEFT: 247px; POSITION: absolute; TOP: 176px" runat="server" Font-Underline="True" Font-Size="X-Large" Font-Bold="True">License Report</asp:label>&nbsp;
            <asp:label id="lblLicense" style="Z-INDEX: 102; LEFT: 86px; POSITION: absolute; TOP: 309px" runat="server"></asp:label>

    This way, everything on my form that is asp code gets printed.

    Now you create a "Print.aspx" page.

    The Print.aspx page is just a blank page with the following as its html code:
                <script language="JavaScript">
                     function GetPrintContent()
                            var PrintDiv =  document.getElementById('printcontent');
                            var ContentDiv =  window.opener.document.getElementById('contentstart');
                            PrintDiv.innerHTML = ContentDiv.innerHTML;
          <body onload="GetPrintContent();">
                <table cellSpacing="0" cellPadding="0" border="0" height="140" width="700" style="LEFT: 1px; POSITION: absolute; TOP: 15px">
                            <td><IMG height="140" src="../images/template/osulogo.gif" width="700">
                <div id="printcontent">

    So, when the user opens the print.aspx page, whatever is displayed on your original form (between the "div" tags) will be transferred over to, and displayed on the print.aspx page.  The user can then select print from the internet explorer menu. =)

    I hope this helps, like I said my form was getting cut off on the right b/c I had the navigation menu on the left.  Yours may not be set up the same way.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    6 Surprising Benefits of Threat Intelligence

    All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

    I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
    1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!

    758 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    13 Experts available now in Live!

    Get 1:1 Help Now