1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
| <div class="col-xs-12">
<div id="content">
<span class="text-left"> text 1 </span>
<span > text 2 </span>
<?php foreach($devisPDF as $PDFdevis) { ?>
<h4><?php echo $PDFdevis['client_societe'] ?></h4>
<p><?php echo $PDFdevis['client_adresse'] ?></p>
<p><?php echo $PDFdevis['client_codepostal']. ' ' .$PDFdevis['client_ville']; ?></p>
<?php break; } ?>
<h2 class="text-right">Export from HTML</h2>
<p>This is a demo for exporting PDF from html using jsPDF. Click save <code>button</code> to export this content.</p>
<br>
<p>Also checkout <a href="https://github.com/simonbengtsson/jsPDF-AutoTable">jsPDF-Autotable</a> for generating PDF tables with more customizable options.</p>
<table id="demo" class="table table-bordered" style="width:1100px;">
<thead>
<tr class='warning'>
<th width="10%">Ref Article</th>
<th width="10%">Désign Article</th>
<th width="10%">Unite</th>
<th width="10%">Prix Unitaire</th>
<th width="10%">Quantité</th>
<th width="10%">Prix Net U</th>
<th width="10%">Total</th>
</tr>
</thead>
<tbody>
<?php foreach($devisPDF as $PDFdevis) { ?>
<tr>
<td><?php echo $PDFdevis['article_ref'] ?></td>
<td><?php echo $PDFdevis['article_designationarticle'] ?></td>
<td><?php echo $PDFdevis['article_pu'] ?></td>
<td><?php echo $PDFdevis['article_unite'] ?></td>
<td><?php echo $PDFdevis['article_quantite'] ?></td>
<td><?php echo $PDFdevis['article_pu'] ?></td>
<td><?php echo $PDFdevis['article_total'] ?></td>
</tr>
<?php } ?>
</tbody>
</table>
</div>
<div class="modal-footer" style="text-align:center;">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Retour</button>
<button class="btn btn-primary" id="export">Exporter en PDF</button>
</div>
</div>
<script>
document.getElementById('export').addEventListener('click', exportPDF);
var specialElementHandlers = {
// element with id of "bypass" - jQuery style selector
'.no-export': function(element, renderer) {
// true = "handled elsewhere, bypass text extraction"
return true;
}
};
function exportPDF() {
var doc = new jsPDF('p', 'pt', 'a4');
var source = document.getElementById('content').innerHTML;
var margins = {
top: 10,
bottom: 10,
left: 10,
width: 800
};
doc.fromHTML(
source, // HTML string or DOM elem ref.
margins.left,
margins.top, {
'width': margins.width,
'elementHandlers': specialElementHandlers
},
function(dispose) {
// dispose: object with X, Y of the last line add to the PDF
// this allow the insertion of new lines after html
doc.save('devis.pdf');
}, margins);
}
</script>
</div>
</div> |
Partager