I am using jsPDF and it uses html2canvas to generate an image from some html element and insert on the .pdf file. But there is a problem on html2canvas, it generates blurry images from the html. See example below:
HTML content:
html2canvas generated image:
Is there any way to fix it or is there any better option to get the image form html?
thanks!
you can use scale options in html2canvas.
In the latest release, v1.0.0-alpha.1, you can use the scale option to increase the resolution (scale: 2 will double the resolution from the default 96dpi).
This is what fixed it for me. And it wasn't because I was using a retina display (because I don't have one):
https://github.com/niklasvh/html2canvas/issues/576
Just change the getBounds() method in html2canvas.js with this one:
I had this problem because I was on a retina display. I solved in by using MisterLamb's solution here.
HTML and PNG without scaling
HTML and PNG with scaling
I have found out my problem. Happens that my screen is a Retina Display, so when the canvas2html will render the HTML, due to the difference of pixel density on retina screen, the image is rendered blurred.
Found out the solution here:
https://github.com/cburgmer/rasterizeHTML.js/blob/master/examples/retina.html
Try the Canvas2Image library, it gives a better quality image at least for me div to image (fiddle).
Good luck!