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

我希望这会有所帮助吗?

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...