Jspdf发布的内容在大的时候没有显示到另一个页面

时间:2018-04-24 20:00:14

标签: javascript jquery

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函数,但它命令内容到一行并不支持bootstrap? 我还尝试过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>

1 个答案:

答案 0 :(得分:0)

我可能迟到了现场,但这就是我想出的...

 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