html - How to print local pdf file using javascript -
for example, having local pdf file contains 6 pages. if using window.print()
function, in print preview shown 1 page ever in browser. instead of single page have show pages in print preview mode.
bind required pages or data around div , print div instead , printing div have place of code.
<html> <head> <script type="text/javascript" src="http://jqueryjs.googlecode.com/files/jquery-1.3.1.min.js" > </script> <script type="text/javascript"> function printelem(elem) { popup($(elem).html()); } function popup(data) { var mywindow = window.open('', 'my div', 'height=400,width=600'); mywindow.document.write('<html><head><title>my div</title>'); /*optional stylesheet*/ //mywindow.document.write('<link rel="stylesheet" href="main.css" type="text/css" />'); mywindow.document.write('</head><body >'); mywindow.document.write(data); mywindow.document.write('</body></html>'); mywindow.document.close(); // necessary ie >= 10 mywindow.focus(); // necessary ie >= 10 mywindow.print(); mywindow.close(); return true; } </script> </head> <body> <div id="mydiv"> printed. lorem ipsum dolor sit amet, consectetur adipiscing elit. pellentesque quam @ nibh adipiscing interdum. nulla vitae accumsan ante. </div> <div> not printed. </div> <div id="anotherdiv"> nor this. </div> <input type="button" value="print div" onclick="printelem('#mydiv')" /> </body> </html>
Comments
Post a Comment