我创建了html表,并尝试使用jsPDF生成pdf。
我使用了以下代码:
var pdf = new jsPDF('p','pt','a4');
pdf.addHTML(document.getElementById('pdfTable'),function() {
console.log('pdf generated');
});
pdf.save('pdfTable.pdf');我得到了空白的pdf文件。我做错什么了吗?
这是一个用于此的plunker。
jsPDF的Working demo与addHTML函数。
发布于 2015-06-14 15:02:57
更新:我已经更新了柱塞器,并使用addHTML()函数使其工作:
var pdf = new jsPDF('p','pt','a4');
//var source = document.getElementById('table-container').innerHTML;
console.log(document.getElementById('table-container'));
var margins = {
top: 25,
bottom: 60,
left: 20,
width: 522
};
// all coords and widths are in jsPDF instance's declared units
// 'inches' in this case
pdf.text(20, 20, 'Hello world.');
pdf.addHTML(document.body, margins.top, margins.left, {}, function() {
pdf.save('test.pdf');
});有关更多详细信息,请访问plunker。
发布于 2015-03-06 18:08:07
在app.js中更改此设置:
pdf.addHTML(document.getElementById('pdfTable'),function() {
});
pdf.save('pdfTable.pdf');对于这一条:
pdf.addHTML(document.getElementById('pdfTable'),function() {
pdf.save('pdfTable.pdf');
});发布于 2015-03-13 08:12:38
我把所有的东西都拿出来了:
<script src="//mrrio.github.io/jsPDF/dist/jspdf.debug.js"></script>
<script src="//html2canvas.hertzen.com/build/html2canvas.js"></script>然后我使用了这个:
$(document).ready(function() {
$("#pdfDiv").click(function() {
var pdf = new jsPDF('p','pt','letter');
var specialElementHandlers = {
'#rentalListCan': function (element, renderer) {
return true;
}
};
pdf.addHTML($('#rentalListCan').first(), function() {
pdf.save("rentals.pdf");
});
});
});我可以打印表格..。在chrome,safari或firefox上看起来很棒,但是,如果我的表格非常大,我只会得到第一页。
https://stackoverflow.com/questions/27047365
复制相似问题