GithubHelp home page GithubHelp logo

html2png's Introduction

html2png

Take a screenshot of a HTML fragment or URL

build status

Installation

This module is installed via npm:

$ npm install html2png

Example Usage

Render some HTML into a PNG Buffer Object

var html2png = require('html2png');
var screenshot = html2png({ width: 1280, height: 720, browser: 'phantomjs'});
screenshot.render('<b>Hello</b>', function (err, data) {
  // If there is an error close the web browser first before calling the
  // errback
  if (err) return screenshot.error(err, cb);

  // data will contain a screenshot of the HTML as a node.js Buffer
  console.log(data);
  //<Buffer 89 50 4e 47 0d 0a 1a 0a 00 00 00 0d 49 48 44 52 00 00 02 80 ...>

  // Close the web browser (phantomjs or chrome)
  screenshot.close(done);
});

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 than height the screenshot returned will be the full rendered height of the page.
  • browser - The browser to use for rendering. By default this is phantomjs and this module bundles together a static binary of phantomjs with phantomjs-bin. If you have Google Chrome installed and chromedriver is in your PATH, 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.

html2png's People

Contributors

eugeneware avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.