Wednesday, 3 May 2017

Customized web page print using Java Script

Printing a webpage is another important aspect of web development. If you skip this section then when your user will be print a page then it will print as it is, which not good for all case because we add a lot of formatting images on webpage. So all the things on the page will get printed that will be worse.

Customizing web page output is good practice to make a webpage. Because what we see on web page we don’t need to take output on paper same format so customization is mandatory.

Following example will print table as with custom header.

Roll Name City
101 Sona Vns
102 Amit Alld
103 Sumi Alld
104 Rakesh Vns
105 Jyoti alld


<table border="1" cellspacing="0" cellpadding="5" id="tb">
</table><br />
<input type="button" value="Print" onclick="print()" />

Java Script Code 

      function print()
             var data=document.getElementById("tb")
             pwindow.document.write("<h1 align='center'>Girfa Student Help Print Demo</h1><hr><br>");

Print Table with Custom Border

var data = document.getElementById("tableId")
data.border = 1;
data.cellSpacing = 0;
data.cellPadding = 2; = 'collapse';

pwindow ="");
pwindow.document.write("<h2 align='center'>Invoice List</h2><hr><br><br>");
pwindow.document.write("<center>" + data.outerHTML + </center>");

Hide last column

$(document).ready(function () {

        $('table tr td:last-child').hide();
        $('table tr th:last-child').hide();