I am trying to ignore a div while exporting to pdf via jsPDF.
Here is my code:
HTML:
<div id="print-this">
<p>Text to print</p>
<div id="ignore">
<p>Text To ignore</p>
</div>
<p>More text to print</p>
</div>
<button id="cmd">Print</button>
$(function () {
$('#cmd').click(function () {
var doc = new jsPDF();
var elementHandler = {
'#ignore': function (element, renderer) {
return true;
}
};
doc.addHTML($('#print-this')[0], 15, 15, {
'background': '#fff',
}, function() {
doc.save('sample.pdf');
});
});
});
Super dirty but does the trick:
$(function() {
$('#cmd').click(function() {
$('#ignore').hide(); //before the addHTML()
var doc = new jsPDF();
doc.addHTML($('#print-this')[0], 15, 15, {
'background': '#fff',
}, function() {
doc.save('sample.pdf');
});
$('#ignore').show(); //and directly after its finished
});
});