我试图用这个打印当前的页码:https://github.com/MrRio/jsPDF/pull/260
但jsPDF渲染了大量的空白页面和崩溃:(
没有页脚,每件事情都运行良好,我得到一个很好的PDF,有27页,但没有页脚因为
控制台错误:
我的页脚是:
<footer>
<div style='text-align:center;'>Page <span class="pageCounter"></span>/<span class="totalPages"></span></div>
</footer>
并且我的Jquery部分:
var doc = new jsPDF();
var margins = {
top: 10,
left: 10,
right: 10,
bottom: 20,
width: 265
};
doc.setProperties({
title: 'Title',
subject: 'This is the subject',
author: 'Author Name',
keywords: 'generated, javascript, web 2.0, ajax',
creator: 'Creator Name'
});
length = doc.internal.getNumberOfPages()
doc.fromHTML(response, margins.left, margins.top,{
'width': margins.width // max width of content on PDF
},
function(){
doc.save('noter.pdf');
}, margins);
很奇怪!但显然,页脚需要有一个<p>
标签才能使其正常工作,即使在github页面的示例中它不是那样的...
所以我改变了
<footer>
<div style='text-align:center;'>Page <span class="pageCounter"></span>/<span class="totalPages"></span></div>
</footer>
至
<footer>
<div><p>Page <span class="pageCounter"></span>/<span class="totalPages"></span></p></div>
</footer>
它现在有效