10

I did my homework and search several times how to make a "screenshot" of a div or any element on html.

html2canvas works nice but I have problems with: - The quality of the image generated. - If the div have images stored on other domains. - Some elements like rounded divs (inside de main div) are generated squared.

Is there any alternative? Don't discard paid alternatives.

Thanks!!!

Car Lautaro
  • 301
  • 1
  • 2
  • 8

4 Answers4

18

See if this DOM-to-Image works for you - https://github.com/tsayen/dom-to-image

It's a library written in JavaScript which can turn arbitrary DOM node into a vector (SVG) or raster (PNG or JPEG) image.

Abhishek K
  • 381
  • 4
  • 10
5

I've used both html2canvas and dom-to-image, they both works well, but it seems that dom-to-image works better with images and has better predictability.

Frank Guo
  • 547
  • 7
  • 8
3

You could look into http://phantomjs.org/, specifically the https://github.com/ariya/phantomjs/blob/master/examples/rasterize.js example where you are able to save HTML to an image or PDF - effectively creating a screenshot. It is very customisable and I have used this to create PDFs from lists of URLs with ease. It is a server side solution, so would need a little more setup your end.

Luke P
  • 723
  • 7
  • 19
2

rasterizeHTML.js renders HTML into the browser's canvas

https://cburgmer.github.io/rasterizeHTML.js/

Vitalicus
  • 1,188
  • 13
  • 15