如何解决jsPDF v2.1.1-doc.html不是函数-10.2020
今天是2020年10月31日,我已经阅读过文档,但是老实说,我不懂百分百的语言,否则我应该回答我。
我看到一条评论说:@HackbrettXXX在26天前评论了
fromHTML已过时。改用html。
doc:https://github.com/MrRio/jsPDF
我尝试使用 doc.html($('#pdfprintcontentarea')。html(),15、15,{
或仅 html($('#pdfprintcontentarea')。html(),15、15,{
但到目前为止还没有成功。
图书馆有新的更新,我不知道该如何解决。
运行同一示例: https://codepen.io/AshikNesin/pen/KzgeYX
这是我正在使用的非常简单的脚本,并且有运行代码解码器的示例。
printpagepdfsimple.js
$(document).ready(function() {
var doc = new jsPDF();
console.log(doc)
var specialElementHandlers = {
'#editor': function(element,renderer) {
return true;
}
};
$('#cmd').click(function() {
doc.fromHTML($('#pdfprintcontentarea').html(),15,{
'width': 170,'elementHandlers': specialElementHandlers
});
doc.save('sample-file.pdf');
});
});
控制台中的错误消息:
Uncaught TypeError: Cannot read property '1' of undefined
at f.renderParagraph (jspdf.153.min.js?ver=1.0.0:202)
at f.setBlockBoundary (jspdf.153.min.js?ver=1.0.0:202)
at k (jspdf.153.min.js?ver=1.0.0:202)
at k (jspdf.153.min.js?ver=1.0.0:202)
at k (jspdf.153.min.js?ver=1.0.0:202)
at k (jspdf.153.min.js?ver=1.0.0:202)
at k (jspdf.153.min.js?ver=1.0.0:202)
at k (jspdf.153.min.js?ver=1.0.0:202)
at jspdf.153.min.js?ver=1.0.0:202
at l (jspdf.153.min.js?ver=1.0.0:202)
f.renderParagraph @ jspdf.153.min.js?ver=1.0.0:202
f.setBlockBoundary @ jspdf.153.min.js?ver=1.0.0:202
k @ jspdf.153.min.js?ver=1.0.0:202
k @ jspdf.153.min.js?ver=1.0.0:202
k @ jspdf.153.min.js?ver=1.0.0:202
k @ jspdf.153.min.js?ver=1.0.0:202
k @ jspdf.153.min.js?ver=1.0.0:202
k @ jspdf.153.min.js?ver=1.0.0:202
(anonymous) @ jspdf.153.min.js?ver=1.0.0:202
l @ jspdf.153.min.js?ver=1.0.0:202
d @ jspdf.153.min.js?ver=1.0.0:202
m @ jspdf.153.min.js?ver=1.0.0:202
t.fromHTML @ jspdf.153.min.js?ver=1.0.0:202
(anonymous) @ printpagepdfsimple.js?ver=1.0.0:10
dispatch @ jquery-2.1.3.min.js?ver=1.0.0:3
r.handle @ jquery-2.1.3.min.js?ver=1.0.0:3
我正在使用wordpress内部的库,但这应该可以在任何地方使用。 链接:
1°
function p5_jQuery_Lib(){
wp_enqueue_script('jQueryLib',get_stylesheet_directory_uri() . '/assets/js/jquery-3.5.1.min.js',array( 'jquery' ),'1.0.0',true );
wp_enqueue_script('jQueryLibalt',get_stylesheet_directory_uri() . '/assets/js/jquery-2.1.3.min.js',true );
}
add_action( 'wp_enqueue_scripts','p5_jQuery_Lib' );
2°
function p5_js_153(){
wp_enqueue_script('printpdf153',get_stylesheet_directory_uri() . '/assets/js/jspdf.153.min.js',true );
}
add_action( 'wp_enqueue_scripts','p5_js_153' );
我在做什么错了?
提前感谢您的帮助!
解决方法
fromHTML
函数似乎已被弃用,但是这也意味着它不再可用。因此,与其继续尝试像这样使用fromHTML
,
doc.fromHTML($('#pdfprintcontentarea').html(),15,{
'width': 170,'elementHandlers': specialElementHandlers
});
您可以尝试以下方法,
doc.html($('#pdfprintcontentarea'),{
x: 15,y: 15,});
我希望这会有所帮助吗?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。