A wrapper for the wkhtmltopdf HTML to PDF converter using WebKit
npm install html2imavertorBase on wkhtmltopdf and Mupdf.
Use wkhtmltopdf: convert html to pdf or image.
Use mupdf: convert pdf to image(hiquality).
1. Install lib wkhtmltopdf 13.02(https://wkhtmltopdf.org)
2. Install lib Mupdf 9.7b(https://wkhtmltopdf.org)
var Convert = require('htmltoimavetor');var html2image = Convert.html2image;
var html2pdf = Convert.html2image;
var pdf2image = Convert.html2image;
`$3
`
// URL
html2image('http://google.com/', { pageSize: 'letter' })
.pipe(fs.createWriteStream('image-out.png'));
// HTML
html2image('Image
Hello world
')
.pipe(res);// Stream input and output
var stream = html2image(fs.createReadStream('html-in.html'));
// output to a file directly
html2image('http://google.com/', { output: 'image-out.png' });
// Optional callback
html2image('http://google.com/', { pageSize: 'letter' }, function (error, stream) {
// make it
});
`$3
`
// URL
html2pdf('http://google.com/', { pageSize: 'letter' })
.pipe(fs.createWriteStream('image-out.pdf'));
// HTML
html2pdf('Image
Hello world
')
.pipe(res);// Stream input and output
var stream = html2pdf(fs.createReadStream('html-in.html'));
// output to a file directly
html2pdf('http://google.com/', { output: 'image-out.png' });
// Optional callback
html2pdf('http://google.com/', { pageSize: 'letter' }, function (error, stream) {
// make it
});
`
$3
`
var file = './pdf-in.pdf';
var options = {
c: 'rbg', // color space: 'rbg', 'rgba', 'cmyk', 'gray'
r: 72, // resolution: by pixel.
output: './image-out.png'
}
// output to a file directly
pdf2image(file, options, function(){
// out file
});
``