Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I render html content as pdf file using phantomJs in node.JS

How can I generate a pdf file with some html content and render the file and content to the browser using phantom.js in node.js?

like image 266
Syam Danda Avatar asked May 14 '16 07:05

Syam Danda


1 Answers

Why not use the html-pdf npm module which uses phantomJS?

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' } 
});
like image 128
Tal Avissar Avatar answered Sep 17 '22 18:09

Tal Avissar