Print a div contents in Php

If You want to print the section or Div contents, then please do the following…

By using the following code you can print the contents in a div or section.

 

Html  Section:

// The Printing button. On click this button the print preview opens


<div class="row">
      <div class="col-md-12"> 
              <button class="xshr_print_section_btn" onclick="javascript:printDivContents('xshr_print_section')">Print Details</button></div>
</div>

<!-- html Ends -->

Script Section:

<!-- For Print the Contents Starts -->

<script language="javascript" type="text/javascript">

function printDivContents(divID) {

//Get the HTML of div
var divElements = document.getElementById(divID).innerHTML;

//Get the HTML of whole page
var oldPage = document.body.innerHTML;

//Reset the page's HTML with div's HTML only
document.body.innerHTML = 
"<html><head><title></title></head><body>" + 
divElements + "</body>";

//Print Page
window.print();

//Restore orignal HTML
document.body.innerHTML = oldPage;


}
</script>

<!-- For Print the Contents / Ends-->

 

 

also solution available at: how to print a Div content in javascript