Cross-platform downloader for the wkhtmltox binaries.
Install package: npm install wkhtmltox-binary --save
.
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.
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'));
});
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'
});