首页 > 解决方案 > Jspdf问题内容很大时不显示到另一个页面

问题描述

I am using jspdf here is my code problem is when content is large it does not show content to next page i am trying it from a week doesn't find answer please help ?

我也尝试过 fromhtml 功能,但它订购内容到一行不支持引导程序?我也尝试过 pageSplit 拉伸内容并使其模糊?

<script>
    function gen(){
    let doc = new jsPDF('p','pt','a4');

    doc.addHTML(document.getElementById('booking_review'),function() {
        var hei=$('#booking_review').height();

        if(hei > 1498){
        alert("height");
        doc.addPage();
        doc.save('html.pdf');
        }
        else{   
        doc.save('html.pdf');
        }
    });
    }
    </script>

标签: javascriptjquery

解决方案


我可能会迟到,但这就是我想出的……

 var doc = new jsPDF("p", "mm", "a4");

 var imgWidth = 210; // The width of jsPDF file. If you want the content to match the page's width
 var pageHeight = 295; // 

 var frameHeight = canvas.height // eg. $('#booking_review').height();
 var frameWidth = canvas.width // $('#booking_review').width();


 var imgHeight = frameHeight * imgWidth / frameWidth
 var heightLeft = imgHeight
 var heightPosition = 0


 doc.addImage(this.src, 'JPEG', 0, heightPosition, imgWidth, imgHeight);
 heightLeft -= imgHeight

 while(heightLeft >= 0){
     heightPosition = heightLeft - pageHeight;
     doc.addPage();
     doc.addImage(this.src, 'JPEG', 0, heightPosition, imgWidth, imgHeight);
     heightLeft -= imgHeight
 }

doc.save('html.pdf')

这对我有用...只需尝试根据自己的喜好调整它:D


推荐阅读