How do I get a multi-page pdf from a website using jsPDF and HTML2Canvas?

前端 未结 5 1907
生来不讨喜
生来不讨喜 2021-02-19 05:03

I have a script that uses HTML2Canvas to take a screenshot of a div within the page, and then converts it to a pdf using jsPDF.

The problem is the pdf that

5条回答
  •  野趣味
    野趣味 (楼主)
    2021-02-19 05:36

    you can use page split option of addhtml like this:

    var options = {
        background: '#fff',
        pagesplit: true
    };
    
    var doc = new jsPDF(orientation, 'mm', pagelayout);
    doc.addHTML(source, 0, 0, options, function () {
            doc.save(filename + ".pdf");
            HideLoader();`enter code here`
    });
    

    Note: This will break the html on multiple pages but these pages will get stretched. Stretching is a issue in addhtml till now and i am still not able to find on internet how to solve this issue.

提交回复
热议问题