Giter Site home page Giter Site logo

node-wkhtmltoimage's Introduction

node-wkhtmltoimage

A Node.js wrapper for the wkhtmltoimage command line tool. It converts HTML documents to images using WebKit. This was originally based on node-wkhtmltopdf.

Usage

var wkhtmltoimage = require('wkhtmltoimage');

// Optionally specify binary path
var wkhtmltoimage = require('wkhtmltoimage').setCommand(__dirname + '/bin/wkhtmltoimage');

// URL
wkhtmltoimage.generate('http://example.com/', { pageSize: 'letter' })
  .pipe(fs.createWriteStream('out.jpg'));

// HTML
wkhtmltoimage.generate('<h1>Hello world</h1>')
  .pipe(res);

// output to a file directly
wkhtmltoimage.generate('http://example.com/', { output: 'out.jpg' });

// Optional callback
wkhtmltoimage.generate('http://example.com/', { pageSize: 'letter' }, function (code, signal) {
});
wkhtmltoimage.generate('http://example.com/', function (code, signal) {
});

wkhtmltoimage is just a function, which you call with either a URL or an inline HTML string, and it returns a stream that you can read from or pipe to wherever you like (e.g. a file, or an HTTP response).

There are many options available to wkhtmltoimage. All of the command line options are supported as documented on the page linked to above. The options are camelCased instead-of-dashed as in the command line tool.

There is also an output option that can be used to write the output directly to a filename, instead of returning a stream.

Installation

First, you need to install the wkhtmltoimage (included with wkhtmltopdf) command line tool on your system. The easiest way to do this is to download a prebuilt version for your system.

Then install the node module, use npm:

npm install wkhtmltoimage

Be sure wkhtmltoimage is in your PATH when you're done installing. Alternatively, use .setCommand(path) to specify the binary path.

License

MIT

node-wkhtmltoimage's People

Contributors

timstudd avatar alromh87 avatar

Watchers

James Cloos avatar  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.