How to print a web page in php using javascript
When we are working on a website bit we want to print a web page or specific section or image then you should try this code.This blog will show you how to use JavaScript’s for print a web page. The print() function prints the contents of the current open window. It open a dialog box there are some option for printing that web page you can choose according to you.
Use Below Code:
<!DOCTYPE> <html> <head> <title>PRINT WEBPAGE</title> </head> <body> <div> <input type="button" value="print Full Page" onclick="window.print();" /> <input type="button" value="print a Specific Section" onclick="printDiv('printMe');" /> </div> <div id="printMe">Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum. </div> </body> </html>
<script> function printDiv(divName){ var printContents = document.getElementById(divName).innerHTML; var originalContents = document.body.innerHTML; document.body.innerHTML = printContents; window.print(); document.body.innerHTML = originalContents; } </script>
OutPut :
1. When user will use above code they will get like below image output :
2. When you will click on button print full page you will get like below image output :
3. When you will click on button print a Specific Section you will get like below image output :
For download above code file CLICK HERE