【发布时间】:2016-09-17 17:00:09
【问题描述】:
所以我正在运行此代码以使用 jsPDF 在页面上打印部分,但他一直返回
TypeError: doc.fromHTML 不是函数
function printPDF(object){
var section_id = jQuery(object).parent().find('p').text().substr(0,3).replace('.','_');
if(!jQuery('#contentsection'+section_id).length){
jQuery(object).parent().parent().parent().before('<div id="contentsection'+section_id+'">'+'</div>');
}
var title_block = jQuery(object).parent().parent().parent();
var text_under_title = jQuery(object).parent().parent().parent().next();
jQuery('#contentsection'+section_id).append(title_block);
jQuery('#contentsection'+section_id).append(text_under_title);
var doc = new jsPDF();
var specialElementHandlers = {
'#editor': function (element, renderer) {
return true;
}
};
jQuery('.print-to-pdf').click(function () {
doc.fromHTML(jQuery('#contentsection'+section_id).html(), 15, 15, {
'width': 170,
// 'elementHandlers': specialElementHandlers
});
doc.save('test-file.pdf');
});
}
知道发生了什么或知道我做错了什么的人,我也不知道这些“元素处理程序”是什么。
【问题讨论】:
-
我没有看到任何 printPDF() 调用...“doc”对象在那里定义。而且,似乎 printPDF 函数缺少一个结束括号( } )...从您在此处显示的内容来看。
-
在 onclick 中调用 printPDF,如下函数 appendPdf($){ $('.heading').append(''); }
-
我很难重现这个问题...你能发布你的 HTML 示例吗?
-
我需要它...因为我在本地测试中“伪造”了一个父层次结构和一个 p id。 PDF 已创建……奇怪的是,第二次点击两次。
标签: javascript wordpress printing jspdf