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".
下的所有内容
超级脏,但确实有效:
$(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
});
});
$("#btnPrint").click(function () {
$(".canhide").hide();
makePDF();
setTimeout(function () {
$(".canhide").show();
}, 5000);
});
我有一个问题,在生成多个页面时,简单的 $(".canhide").show();
after makePDF()
不会隐藏不必要的内容。 setTimeout
函数救了我。
我试图在通过 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".
下的所有内容超级脏,但确实有效:
$(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
});
});
$("#btnPrint").click(function () {
$(".canhide").hide();
makePDF();
setTimeout(function () {
$(".canhide").show();
}, 5000);
});
我有一个问题,在生成多个页面时,简单的 $(".canhide").show();
after makePDF()
不会隐藏不必要的内容。 setTimeout
函数救了我。