带有HTML渲染器的jsPDF多页PDF [英] jsPDF multi page PDF with HTML renderer

查看:196
本文介绍了带有HTML渲染器的jsPDF多页PDF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的站点中使用jsPDF生成PDF.但是现在我可以在单个PDF中打印多个DIV.可能需要2到3页.

I am using jsPDF in my site to generate PDFs. But now I have multiple DIVs to print in a single PDF. which may take 2 to 3 pages.

例如:

<div id="part1">
  content
</div>

<div id="part2">
  content
</div>

<div id="part2">
   content
</div>

我的JS代码

  • 此方法有效,但未达到我的预期,它添加了一部分内容(不能包含在多个页面中).
  • 它会删除br,h1等html标签.
    function formtoPDF() {
      jsPDF.API.mymethod = function() {
        // 'this' will be ref to internal API object. see jsPDF source
        // , so you can refer to built-in methods like so:
        //   this.line(....)
        //   this.text(....)
      };
      var doc = new jsPDF();
      doc.mymethod();
      var pdfPart1 = jQuery('#genPDFpart1');
      var pdfPart2 = jQuery(".ltinerary");
      var pdfPart3 = jQuery("#domElementHTML");
      var specialElementHandlers = {
        '#loadVar': function(element, renderer) {
          return true;
        }
      };
      doc.fromHTML(pdfPart1.html() + pdfPart3.html() + pdfPart3.html(), 15, 15, {
        'width': 170,
        'elementHandlers': specialElementHandlers
      });
      doc.output('save', 'Download.pdf');
    }

我可以为此解决办法吗?在此先感谢朋友.

Can I have a solution for this. Thanks in advance pals .

推荐答案

我遇到了同样的问题.在MrRio github中搜索时,我发现: https://github.com/MrRio/jsPDF/issues/101

I have the same working issue. Searching in MrRio github I found this: https://github.com/MrRio/jsPDF/issues/101

基本上,您必须在添加新内容之前始终检查实际页面大小

Basically, you have to check the actual page size always before adding new content

doc = new jsPdf();
...
pageHeight= doc.internal.pageSize.height;

// Before adding new content
y = 500 // Height position of new content
if (y >= pageHeight)
{
  doc.addPage();
  y = 0 // Restart height position
}
doc.text(x, y, "value");

这篇关于带有HTML渲染器的jsPDF多页PDF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆