JsPdf using html2canvas.js to export pdf from html does not work for big data

Hi, I use jsPdf to create html pdf content, it is great for short content and pdf creation, but when I try to use it on large content with html2canvas.js (for css rendering), it is not creating pdf. Any suggestions or sample code for this would be helpful. Thank.

+1
source share
2 answers

PDF creation for large files is possible. There are basically two ways to do this:

1. html -> canvas -> image -> pdf (I assume you are trying to use this approach)

2.html -> pdf (does not work if html contains svg)

(2), (1) (, svg) - , .

1. html → canvas → image → pdf

- https://github.com/MrRio/jsPDF/issues/339#issuecomment-53327389

- , pdf 2-3 . ( firefox)

2. html → pdf

var pdf = new jsPDF('l', 'pt', 'a4');
 var options = {
    pagesplit: true
};

pdf.addHTML($('body'), 0, 0, options, function(){
    pdf.save("test.pdf");
});

. PDF , 5-6 1-2 !

, !

+5

PDFPY

https://www.npmjs.com/package/pdfpy

var data = {
    //the key as to be same as below
    input: "./test.html",
    output: "./output.pdf"
}

pdfpy.file(data, function(err, res) {
    if(err) throw err

    if(res) console.log("success")
});
+1

All Articles