【问题标题】:export html div into pdf with jspdf使用 jspdf 将 html div 导出为 pdf
【发布时间】:2014-07-28 08:35:22
【问题描述】:

我有这个代码,但不起作用。控制台返回这个错误:

无法读取未定义的属性“宽度” - jspdf.plugin.from_html.js:169

有人可以帮助我吗?

<div id="box">
    Lorem ipsum dolor sit amet, consectetur adipisicing elit,
    sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. 
    Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi...
</div>


<button id="pdf_new"> New PDF</button>

<!-- Analytics -->
<script type="text/javascript">

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

   $('#pdf_new').click(function(){
      var html=$("#box").html();
         doc.fromHTML(html,200,200, {
            'width': 500,
            'elementHandlers': specialElementHandlers
         });
      doc.save("Test.pdf");
    });


</script>

在这里你可以找到jspdf.plugin.from_html.js,问题在这个文件的第720行

【问题讨论】:

  • 您能否在jsfiddle.net 上提供一个工作示例?如果不知道在这种情况下undefined 实际上应该是什么,很难在这里为您提供帮助
  • 添加到 jspdf.plugin.from_html.js 文件的链接
  • 同样的问题 JsPDF 也不支持表 colspan

标签: javascript html pdf jspdf


【解决方案1】:

我发现了问题,我没有包含所有jsPDF库的主要文件。现在可以了!!

【讨论】:

  • 请提供完整的答案,让我们知道您添加了哪些 JsPDF 的“所有”“主文件”以使其正常工作。?
猜你喜欢
  • 1970-01-01
  • 2014-05-26
  • 1970-01-01
  • 1970-01-01
  • 2021-10-15
  • 2018-01-07
  • 2013-11-17
  • 1970-01-01
  • 2014-06-25
相关资源
最近更新 更多