jsPDF没有忽略div(jsPDF not ignoring div)

我试图通过jsPDF导出到pdf时忽略div。 这是我的代码:

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>

jQuery的:

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

它不是忽略特定的ID,而是在id =“print-this”下导出所有内容。

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>

Jquery:

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

Instead of ignoring a specific id it is exporting everything under id="print-this".

最满意答案

超级肮脏,但诀窍:

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

的jsfiddle

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

JsFiddle

jsPDF没有忽略div(jsPDF not ignoring div)

我试图通过jsPDF导出到pdf时忽略div。 这是我的代码:

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>

jQuery的:

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

它不是忽略特定的ID,而是在id =“print-this”下导出所有内容。

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>

Jquery:

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

Instead of ignoring a specific id it is exporting everything under id="print-this".

最满意答案

超级肮脏,但诀窍:

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

的jsfiddle

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

JsFiddle