Reputation: 798
How can I use hummusJS to convert HTML code to PDF?
So far I am able to convert JPG images to pdf, as well as merge multiple pdfs.
Upvotes: 2
Views: 1358
Reputation: 2235
puppeteer is a good solution:
Installation
npm i puppeteer
# or "yarn add puppeteer"
Example - create a PDF.
const puppeteer = require('puppeteer');
(async () => {
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.goto('https://news.ycombinator.com', {waitUntil: 'networkidle2'});
await page.pdf({path: 'hn.pdf', format: 'A4'});
await browser.close();
})();
Upvotes: 1
Reputation: 2235
try to use html-to-pdf-converter
Using headless chrome via puppeteer and than modifying generated pdf via HummusJS to add headers and footers with page numbers
Install
npm install html-to-pdf-converter
For me node-html-pdf with phantomjs is the best.
Install
npm install -g html-pdf
code example:
var fs = require('fs');
var pdf = require('html-pdf');
var html = fs.readFileSync('./test/businesscard.html', 'utf8');
var options = { format: 'Letter' };
pdf.create(html, options).toFile('./businesscard.pdf', function(err, res) {
if (err) return console.log(err);
console.log(res); // { filename: '/app/businesscard.pdf' }
});
Upvotes: 0