Friday, 7 September 2012

Print and Print preview of webpage in Asp.net

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script type="text/javascript" language="javascript">
function displayMessage(printContent) {
var inf = printContent;
win = window.open("print.htm", 'popup', 'toolbar = no, status = yes, scrollbars=1');
win.document.write(inf);
win.document.close(); // new line
}
</script>
<style type="text/css" media="screen">
.PrintButton{
display:block;
}
    .style1
    {
        width: 1180px;
        height: 516px;
    }
    .style2
    {
        width: 1184px;
        height: 768px;
    }
</style>
<style type="text/css" media="print">
.PrintButton{
display:none;
}
</style>
     <script type="text/javascript">
         function revertback() {
             window.close();
         }
         window.onafterprint = revertback
     
</script>

</head>
<body>
    <form id="form1" runat="server">
    <div>
    <div id="printarea"><br />
    <center>
        <img alt="" class="style1" src="Images/Chrysanthemum.jpg" /><br />
        <img alt="" class="style2" src="Images/Desert.jpg" /><br />
        ddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd<br />
        fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff<br />
        fffffffffffffffffffffffffffffffffffffffffffff<br /></center>
        </div>
    <a href="javascript:void();" onclick="displayMessage(printarea.innerHTML)">Print Preview</a>
        <br />
        <br />
    </div>
    <input id="btnPrint" type="button" value="Print" class="PrintButton" onclick="window.print();" />
    </form>
</body>
</html>

No comments:

Post a Comment