微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

jsPDF v2.1.1-doc.html不是函数-10.2020

如何解决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内部的库,但这应该可以在任何地方使用。 链接

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

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 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?