Print report content as PDF

This commit is contained in:
coolneng 2020-07-15 23:44:44 +02:00
parent 1993b0d27e
commit 5fab7775d4
Signed by: coolneng
GPG Key ID: 9893DA236405AF57
4 changed files with 339 additions and 18 deletions

View File

@ -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);
}

48
src/print_page.js Normal file
View File

@ -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();
}

View File

@ -7,7 +7,9 @@
<meta name="description" content=""> <meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1"> <meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="static/style.css" type="text/css" media="screen" /> <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> </head>
<body> <body>
<?php include 'navbar.php'; ?> <?php include 'navbar.php'; ?>
@ -50,10 +52,10 @@
<a href="report_management.php?delete=<?php echo $row[0]; ?>" class="del_btn">Borrar</a> <a href="report_management.php?delete=<?php echo $row[0]; ?>" class="del_btn">Borrar</a>
</td> </td>
<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>
<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> </td>
</tr> </tr>
<?php endforeach ?> <?php endforeach ?>

286
src/static/jspdf.min.js vendored Normal file

File diff suppressed because one or more lines are too long