简体   繁体   English

使用 jspdf 和 html2canvas 的动态 html 的多个 pdf 页面

[英]Multiple pdf pages for dynamic html using jspdf and html2canvas

I got this template and Im trying to make it a pdf using jspdf and html2canvas:我得到了这个模板,我试图用 jspdf 和 html2canvas 把它变成一个 pdf:

<div id="tre" class="letter-content">
    <h5><b>My tittle</b></h5>
    <br>
    <p>My text here
    </p>
    <ul>
        {% for function in functions %}
            <li>
                <p>{{ function.description }}</p>
            </li>
        {% endfor %}
    </ul>

</div>

The pdf creation script is this one: pdf创建脚本是这样的:

    function getPDF(){
        var HTML_Width = 1024;
        var HTML_Height = 768;
        var PDF_Width = 1024
        var PDF_Height = 768
        var canvas_image_width = 1050;
        var canvas_image_height = 950;

        html2canvas(document.getElementById("tre"),{ allowTaint:true}).then(function(canvas) {

            var imgData = canvas.toDataURL("image/jpg", 1);
            var pdf = new jsPDF('p', 'px', [PDF_Height, PDF_Width]);
            pdf.addImage(imgData, 'JPEG', 20, 0, canvas_image_width,canvas_image_height);
            pdf.save("Certificate.pdf");
        });
    }

But as you can see on the template, that "for" statement may create html for one record or for many, getting that when it renders many iterations, the jspdf only gets me only one page always, cutting the rest, how can I make it to create as many pages as it needs ??但是正如您在模板上看到的那样,“for”语句可能会为一条记录或多条记录创建 html,当它呈现多次迭代时,jspdf 总是只让我只有一页,其余的我怎么做它可以根据需要创建尽可能多的页面?

Thanks in advance !!提前致谢 !!

Multiple pages pdf can be generated using jspdf.使用jspdf可以生成多页pdf。 Please refer this link https://stackoverflow.com/a/59320184/9530728 .请参考此链接https://stackoverflow.com/a/59320184/9530728

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM