本文介绍了jsPDF:addHTML方法不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了html表,并尝试使用jsPDF生成pdf.

I created html table and tried to generate pdf using jsPDF.

我使用了以下代码:

var pdf = new jsPDF('p','pt','a4');  
pdf.addHTML(document.getElementById('pdfTable'),function() {
  console.log('pdf generated');
});
pdf.save('pdfTable.pdf');

我正在得到空白的pdf文件.我做错什么了吗?

I am getting blank pdf file. Am I doing anything wrong?

这是一个 plunker .

使用addHTML函数在演示中工作.

Working demo of jsPDF with addHTML function.

推荐答案

plunker 这:更新:我已经更新了插件,并使其与addHTML()函数一起工作:

Made working plunker for this:Update:I have updated the plunker and made it work with addHTML() function:

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

这篇关于jsPDF:addHTML方法不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-14 16:12