【问题标题】:How to place single image on multiple pages by jspdf?如何通过jspdf将单个图像放在多个页面上?
【发布时间】:2015-09-09 10:10:53
【问题描述】:

我的 html 页面包含非常长的数据。

在这里,我必须将 html 转换为 pdf。我无法使用 jspdf 将 pdf 与 css 转换

所以我已经计划好了。先通过canvas将html转为png,再将png转为pdf。我有正确的方法来做到这一点。我也有解决办法。

但问题是转换 png 后,我无法放置在 pdf 中,图像将被裁剪。

这是我的代码

window.onload = function() {
                html2canvas(document.body).then(function(canvas) {
        document.getElementById("page1").appendChild(canvas);
                    document.body.appendChild(canvas);
                    var context = canvas.getContext("2d");
                     l = {
                         orientation: 'p',
                         unit: 'pt',
                         format: 'a3',
                         compress: true,
                         fontSize: 8,
                         lineHeight: 1,
                         autoSize: false,
                         printHeaders: true
                     };

                    var doc = new jsPDF(l, "", "", "");



                    doc.addImage(canvas.toDataURL("image/jpeg"), 'jpeg',0,0)
                    doc.addPage();
            doc.addImage(canvas.toDataURL("image/jpeg"), 'jpeg',0,500, 1000, 1000)
                    window.location=doc.output("datauristring")
                });
            }

转换 pdf 后,我显示在同一个选项卡中。

我尝试了另一种方法。

将 html 页面分成两部分。第一部分将在 pdf 的第一页,其余部分将在 pdf 的第二页。之后,我必须在浏览器中显示。

我做不到。

任何人都可以为此提供解决方案吗?

【问题讨论】:

    标签: javascript html pdf jspdf


    【解决方案1】:

    l = { 方向:'p', 单位:'pt', 格式:'a3', 压缩:真, 字体大小:8, 线高:1, 自动尺寸:假, 打印标题:真 };

    var doc = new jsPDF(l);

    doc.addHTML($('elementHTML'),{format:'png',pagesplit: true}});

    【讨论】:

      猜你喜欢
      • 2020-07-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-11-10
      • 2012-12-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多