html2png
Take a screenshot of a HTML fragment or URL
Installation
This module is installed via npm:
$ npm install html2png
Example Usage
Render some HTML into a PNG Buffer Object
var html2png = ;var screenshot = ;screenshot;
API
html2png([options])
The constructor is passed an options object:
width
,height
- the width and height of the browser. NB: This is not the maximum dimensions of each screenshot. So if the rendered page is higher thanheight
the screenshot returned will be the full rendered height of the page.browser
- The browser to use for rendering. By default this isphantomjs
and this module bundles together a static binary of phantomjs with phantomjs-bin. If you have Google Chrome installed andchromedriver
is in yourPATH
, then you can render with Chrome.
html2png#render(html, cb)
Renderes html
into a PNG node.js Buffer
and returns the data in the
callback.
html2png#renderUrl(url, cb)
Renders the URL url
into a PNG node.js Buffer
and returns the data in the
callback.
html2png#close(cb);
Closes the underlying webdriver web browser used for the rendering (eg. Phantomjs or Chrome). Highly recommended.
html2png#error(err, cb)
Helper method that will call #close
first, before calling the usual errback
with the error.