Search code examples
javascriptjquerycanvashtml2canvasjspdf

JSPDF - addHTML() Multiple Canvas Page


I noticed already have a release "addHTML() can now split the canvas into multiple pages" which can find through this link : https://github.com/MrRio/jsPDF/releases/tag/v1.0.138.

May i know how it work? In my case, i just tried it out when click on "save as pdf" button, it just render a single page instead of multiple pages (sometimes didn't worked, i assume because the content is too long to be generated as pdf).

Would appreciate if there are some examples for this case. Thanks!

Attached my codes below:

var pdf = new jsPDF('p', 'pt', 'a4');

pdf.addHTML($(".pdf-wrapper"), function () {
    var string = pdf.output('datauristring');
    pdf.save("test.pdf");
});

Solution

  • Splitting canvas into multiple pages work by providing a "pagesplit" option:

    var pdf = new jsPDF('p', 'pt', 'a4');
    var options = {
             pagesplit: true
        };
    
    pdf.addHTML($(".pdf-wrapper"), options, function()
    {
        pdf.save("test.pdf");
    });