Below is the Code to print Particular div of html in any browser .From the below code you can adjust even height,width and font for that print.
function printContent(id) {
var height = '260';
var width = '675';
var font = '12';
str = document.getElementById(id).innerHTML
newwin = window.open('', 'printwin')
newwin.document.write('<HTML>\n<HEAD>\n')
newwin.document.write('<TITLE>Print CA</TITLE>\n')
newwin.document.write('<style type="text/css">\n')
newwin.document.write('*{font-size:' + font + 'px;}\n')
newwin.document.write('html { width: ' + width + '; height: ' + height + '; }\n')
newwin.document.write('<\/style>\n')
newwin.document.write('<script>\n')
newwin.document.write('function chkstate(){\n')
newwin.document.write('if(document.readyState=="complete"){\n')
newwin.document.write('window.close()\n')
newwin.document.write('}\n')
newwin.document.write('else{\n')
newwin.document.write('setTimeout("chkstate()",2000)\n')
newwin.document.write('}\n')
newwin.document.write('}\n')
newwin.document.write('function print_win(){\n')
newwin.document.write('window.print();\n')
newwin.document.write('chkstate();\n')
newwin.document.write('}\n')
newwin.document.write('<\/script>\n')
newwin.document.write('</HEAD>\n')
newwin.document.write('<BODY onload="print_win()">\n')
newwin.document.write(str)
newwin.document.write('</BODY>\n')
newwin.document.write('</HTML>\n')
newwin.document.close()
}
Done !! :)
Comments
Post a Comment