Print report content as PDF
This commit is contained in:
parent
1993b0d27e
commit
5fab7775d4
|
@ -1,15 +0,0 @@
|
|||
function printExternal(url) {
|
||||
var printWindow = window.open(url, 'Print', 'left=200, top=200, width=950, height=500, toolbar=0, resizable=0');
|
||||
|
||||
printWindow.addEventListener('load', function() {
|
||||
if (Boolean(printWindow.chrome)) {
|
||||
printWindow.print();
|
||||
setTimeout(function(){
|
||||
printWindow.close();
|
||||
}, 500);
|
||||
} else {
|
||||
printWindow.print();
|
||||
printWindow.close();
|
||||
}
|
||||
}, true);
|
||||
}
|
|
@ -0,0 +1,48 @@
|
|||
function printExternalHTML(url) {
|
||||
var printWindow = window.open(url, 'Print', 'left=200, top=200, width=950, height=500, toolbar=0, resizable=0');
|
||||
|
||||
printWindow.addEventListener('load', function() {
|
||||
if (Boolean(printWindow.chrome)) {
|
||||
printWindow.print();
|
||||
setTimeout(function(){
|
||||
printWindow.close();
|
||||
}, 500);
|
||||
} else {
|
||||
printWindow.print();
|
||||
printWindow.close();
|
||||
}
|
||||
}, true);
|
||||
}
|
||||
|
||||
function getHTML(url){
|
||||
html = null;
|
||||
$.ajax({
|
||||
url: url,
|
||||
async: false,
|
||||
success: function (data) {
|
||||
console.log(data);
|
||||
html = data;
|
||||
}
|
||||
});
|
||||
return html;
|
||||
}
|
||||
|
||||
|
||||
function printExternalPDF(url) {
|
||||
var html = getHTML(url);
|
||||
var pdf = new jsPDF();
|
||||
margins = {
|
||||
top: 80,
|
||||
bottom: 60,
|
||||
left: 40,
|
||||
width: 522
|
||||
};
|
||||
pdf.fromHTML(
|
||||
html,
|
||||
margins.left,
|
||||
margins.top, {
|
||||
'width': margins.width
|
||||
}
|
||||
),
|
||||
pdf.save();
|
||||
}
|
|
@ -7,7 +7,9 @@
|
|||
<meta name="description" content="">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<link rel="stylesheet" href="static/style.css" type="text/css" media="screen" />
|
||||
<script src="print_html.js"></script>
|
||||
<script src="static/jquery-3.5.1.min.js"></script>
|
||||
<script src="static/jspdf.min.js"></script>
|
||||
<script src="print_page.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<?php include 'navbar.php'; ?>
|
||||
|
@ -50,10 +52,10 @@
|
|||
<a href="report_management.php?delete=<?php echo $row[0]; ?>" class="del_btn">Borrar</a>
|
||||
</td>
|
||||
<td>
|
||||
<input type="button" value="HTML" class="create_btn" onClick="printExternal('report_content.php?id=<?php echo $row[0]; ?>')">
|
||||
<input type="button" value="HTML" class="create_btn" onClick="printExternalHTML('report_content.php?id=<?php echo $row[0]; ?>')">
|
||||
</td>
|
||||
<td>
|
||||
<a href="report_management.php?print_pdf=<?php echo $row[0]; ?>" class="create_btn">PDF</a>
|
||||
<input type="button" value="PDF" class="create_btn" onClick="printExternalPDF('report_content.php?id=<?php echo $row[0]; ?>')">
|
||||
</td>
|
||||
</tr>
|
||||
<?php endforeach ?>
|
||||
|
|
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue