Creating a Printer Friendly ASP.NET Page

Here's how to create  printer friendly versions of your ASP.NET pages relatively easy.

Create a DIV which holds the content of your ASP.NET Page , so enclose the entire content that you want to print inside a div -

<div id="ContentDiv">

Then create a Hyperlink for the user to click to get to the print friendly page


<a href="#" onclick="JavaScript:PrintPage('ContentDiv')">Printer Friendly Page</a>

Include this JavaScript Function in your page for printing the webpage


<script type="text/javascript">
    function PrintPage(divID) {
        var windowOptions = "toolbar=no,location=no,directories=yes,menubar=no,";
        windowOptions += "scrollbars=yes,width=750,height=600,left=100,top=25";
        var printContent = document.getElementById(divID);
        var printWindow = window.open("", "", windowOptions);
        printWindow.document.write(printContent.innerHTML);
        printWindow.document.close();
        printWindow.focus();
        printWindow.print();
    }
</script>

 

The printContent.innerHTML will give you all the required data on the page that has to be printed.


Hope this helped


Cheers

0 Responses to "Creating a Printer Friendly ASP.NET Page"

Post a Comment