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>

<!-- 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

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


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



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

How to print a div content

<html> <head></head> <body> <style> .AP_CONTNT{width: 1000px;} .AP_HEAD{border: 1px solid;padding: 7px;background: bisque;} .AP_CONTNT1{border: 1px solid;padding: 7px;margin-top: 5px;background-color: cadetblue;} .AP_CONTNT2{border: 1px solid;padding: 7px;margin-top: 5px;background-color: cadetblue;} .AP_CONTNT2_B1{border: 1px solid;padding: 0px;background: white;} .AP_CONTNT2_BC1{border: 0px solid grey;padding: 7px;margin-top:5px;} .AP_CONTNT2_BC2{border: 0px solid;padding: 7px;margin-top:5px;} .AP_CONTNT2_BC3{border: 0px solid;padding: 7px;margin-top:5px;} .table1{border: 1px solid; width:100%;border-collapse:collapse;} .table1 tr td{border: 1px solid; } .table1 td{padding: 5px;} .div_btn{padding:5px;} … Read moreHow to print a div content