documark / wkhtmltox-binary

[WIP] Cross-platform downloader for the wkhtmltopdf binary.
0 stars 0 forks source link

Wkhtmltox Binary

Cross-platform downloader for the wkhtmltox binaries.

NOTE: This is a work in progress!

Usage

  1. Install package: npm install wkhtmltox-binary --save.

  2. Load package and request specific wkhtmltopdf or wkhtmltoimage version:

    var binary = require('wkhtmltox-binary');
    
    binary('0.12.2.1', function (err, path) {
        // path => /path/to/wkhtmltopdf *
    });
    
    binary(
        { type: 'image', version: '0.12.2.1' },
        function (err, path) {
            // path => /path/to/wkhtmltoimage *
        }
    );

    * Executable file. This has an .exe extension on Windows.

Use with node-wkhtmltopdf package:

Download the binary and set is as the compile command:

var wkhtmltopdf = require('wkhtmltopdf');
var binary      = require('wkhtmltox-binary');

binary('0.12.2.1', function (err, path) {
    if (err) throw err;

    wkhtmltopdf.command = path;

    // .. then compile document:
    wkhtmltopdf('http://google.com/', { pageSize: 'letter' })
        .pipe(require('fs').createWriteStream('out.pdf'));
});

Configuration

These are the available configuration options and their defaults:

binary({
    type: 'pdf',
    version: '0.12.2.1', // Has no default, always specify version!
    cache: true,
    download: true,      // Returns error when false and binary is not available.
}, function (err, path) {
    // err instanceof Error
    // typeof path === 'string'
});

Supported platforms