【发布时间】:2021-06-13 01:43:29
【问题描述】:
我有一个 WordPress 站点,我想用jsPDF 生成一个 PDF。它可以工作,但PDF是空白的。我已经设置了另一个没有 WordPress 的页面,并且它使用相同的代码工作。我用来编码的示例在codepen,但我不是作者。现在我的问题是,jsPDF 不能与 WordPress 一起使用吗?如果还没有,我的错误在哪里?
functions.php
wp_enqueue_script( 'pdf', get_stylesheet_directory_uri() . '/generatePDF.js', array( 'jquery' ),'',true );
wp_enqueue_script( 'jsPDF', 'https://cdnjs.cloudflare.com/ajax/libs/jspdf/1.4.1/jspdf.debug.js', array( 'jquery' ),'',true );
wp_enqueue_script( 'jsPDF-autotable', 'https://cdnjs.cloudflare.com/ajax/libs/jspdf-autotable/2.3.4/jspdf.plugin.autotable.min.js', array( 'jquery' ),'',true );on 04.03.2021
myCustomTemplate.php
<div id='a4' style='height: 297mm; width: 210mm; border: 1px black solid; margin-left:20%;'>
<p>Content of PDF</p>
</div>
生成PDF.js
函数导出PDF() { var doc = new jsPDF('p', 'mm', 'a4');
var specialElementHandlers = {
'#getPDF': function(element, renderer){
return true;
},
'.controls': function(element, renderer){
return true;
}
};
doc.fromHTML(jQuery('#a4').get(0), 15, 15, {
'width': 170,
'elementHandlers': specialElementHandlers
});
doc.save('offerte.pdf');
}
【问题讨论】:
-
@Bhautik 谢谢,但我使用了 html2canvas,我需要一个选项来生成带有文本而不是图片的 PDF。