Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/470.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/85.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript jsPDF总是在控制台上返回jsPDF PubSub错误_Javascript_Jquery_Plugins_Jspdf - Fatal编程技术网

Javascript jsPDF总是在控制台上返回jsPDF PubSub错误

Javascript jsPDF总是在控制台上返回jsPDF PubSub错误,javascript,jquery,plugins,jspdf,Javascript,Jquery,Plugins,Jspdf,我有一个保存html页面的按钮。当用户单击按钮时,我想触发jsPDF函数,但返回“jsPDF PubSub Error”,生成的pdf文件为空 var doc = new jsPDF(); var specialElementHandlers = { '#editor': function(element, renderer){ return true; } }; $('.voucher-actions__save').click(function () {

我有一个保存html页面的按钮。当用户单击按钮时,我想触发jsPDF函数,但返回“jsPDF PubSub Error”,生成的pdf文件为空

 var doc = new jsPDF();
 var specialElementHandlers = {
   '#editor': function(element, renderer){
    return true;
   }
 };

 $('.voucher-actions__save').click(function () {
   doc.fromHTML($('body').html(), 0, 0, {
    'width': 170,
    'elementHandlers': specialElementHandlers
   });
   //doc.save('voucher.pdf');
   console.log(doc);
 });

我对jsPDF也有同样的问题:

将jsPDF从v1.3.5降级到v1.3.1对我有帮助

我现在使用的版本:

<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/1.3.1/jspdf.min.js"></script>

添加下面的代码,它应该可以工作

// #clientPrintContent is the element id which contains print content
// Print Docs
function printPDF() {
    var doc = new jsPDF();
    var elementHandler = {
        '#clientPrintContent': function (element, renderer) {
            return true;
        }
    };
    var source = document.getElementById("clientPrintContent");
    doc.fromHTML(
      source,
      15,
      15,
      {
          'width': 180, 'elementHandlers': elementHandler
      });
    // Output 
    doc.save('sample-file.pdf');
}
您可以从中添加CDN托管库


<script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/1.4.1/jspdf.debug.js" integrity="sha384-THVO/sM0mFD9h7dfSndI6TS0PgAGavwKvB5hAxRRvc0o9cPLohB0wb/PTA7LdUHs" crossorigin="anonymous"></script>