Surendra Sharma

Surendra Sharma

Search This Blog

Wednesday, August 28, 2013

How to open ASP.NET web page in Print mode

I have requirement where user clicked on link in Main page should open another window with view only information. This view only window should be directly open in PRINT mode as below



This can be achieve by using Javascript functions.

Below ASPX page directly opened in Print mode

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>Open Page in Print Mode</title>

    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>

    <script type="text/javascript">
        $(document).ready(function() {
            //Allow page to be load so keep delay of 1 sec and show the print dialogue
            setTimeout(printWindowAfterDelay, 1000);
        });

        function printWindowAfterDelay() {
            window.print();
        }

    </script>

</head>
<body>
    <form id="form1" runat="server">
    <div>
        <div>
            <h1 align="left">
                Open page in print mode</h1>
        </div>
        <div>
            Put your controls here
        </div>
    </div>
    </form>
</body>
</html>


Please leave your comments or share this tip if it’s useful for you.

1 comment:

  1. This is so prehistoric.
    Use iTextSharp, it's free and excellent.

    ReplyDelete