html2canvas not working for large HTML content

Created on 14 Jun 2018  路  5Comments  路  Source: niklasvh/html2canvas

I am trying to use html2canvas library, to save html that's dynamically generated and output to the page as image. If the HTML generated isn't too much, then the html2canvas would work just fine, however, if the html generated is really too big (when I try to print it, it's 70 pages), then the html2canvas will return a canvas object where canvas.toDataURL('image/png') returns data:; and that's it.

I found a post online suggesting to change the maxInt in the html2canvas.js file to be Number.MAX_VALUE, but that didn't work as well.

Is there a way to workaround this issue? I will need this image to eventually pass it to jspdf library to generate a pdf document.

Most helpful comment

Please let me know whether you found a solution. i am getting slowness on generating the Image and converting it into PDF

All 5 comments

You may want to make sure the canvas it creates is within the limitations per browser. See the FAQ:

https://html2canvas.hertzen.com/faq

Each browser has a max size canvas it will create and html2canvas can't do anything about that. So if it's generating fine for smaller sizes, but fails when the content gets too big it could be you running up against these limits.

Check the console as it logs out the size of the canvas it allocates:

html2canvas: Canvas renderer initialized (1024x1934 at 0,0) with scale 1

Please let me know whether you found a solution. i am getting slowness on generating the Image and converting it into PDF

Dear @chubbard, I get Canvas renderer initialized (0x0 at 0,0) with scale 1 on console even though my div is

<div id="capture" style="padding: 10px; background: #f5da55; height: 200px">
    <h4 style="color: #000; ">Hello world!</h4>
</div>

nothing below works then. Could you Please tell me what I am missing. TIA

I hava same issue! if print 15 pages,it works fine,but my target is print 30 pages,the last 15 pages are blank,please let us know whether you found a solution.

I hava same issue! if print 15 pages,it works fine,but my target is print 30 pages,the last 15 pages are blank,please let us know whether you found a solution.

Hi, unable to resolve that issue. so we cancelled that approach. From backend using java & itext we created the PDF.

Was this page helpful?
0 / 5 - 0 ratings