Sometime you need to print any specific area of page so on this blog i will explain how to print any div or table lets go start now
index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>CoderRaj</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
</head>
<body>
<div class="container" >
<div class="row">
<h1>Student List</h1>
<button type="button" OnClick = "return PrintPanel();" ID="btnPrint" class="btn btn-primary">Print</button>
</div>
<div id="printDiv">
<table class="table" >
<tr>
<th>S.No.</th>
<th>Name</th>
<th>City</th>
</tr>
<tr>
<td>1</td>
<td>Rajesh</td>
<td>Raipur</td>
</tr>
<tr>
<td>2</td>
<td>Anurag</td>
<td>Durg</td>
</tr>
<tr>
<td>3</td>
<td>Amit</td>
<td>Bhilai</td>
</tr>
<tr>
<td>4</td>
<td>Pawan</td>
<td>Rajnandgaon</td>
</tr>
</table>
</div>
</div>
</body>
<script type = "text/javascript">
function PrintPanel() {
var panel = document.getElementById("printDiv");
var printWindow = window.open('', '', 'height=400,width=800');
printWindow.document.write('<html><head><link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css"><title>CoderRaj</title>');
printWindow.document.write('</head><body >');
printWindow.document.write(panel.innerHTML);
printWindow.document.write('</body></html>');
printWindow.document.close();
setTimeout(function () {
printWindow.print();
}, 500);
return false;
}
</script>
</html>