node.jspdf

nodejs html-to-pdf, output is not working


The html-to-pdf: https://github.com/ChaosEvoker/html-to-pdf

I want to convert HTML to PDF like this:

var htmlToPdf = require('html-to-pdf');
var html = '<div>test</div>'; //Some HTML String from code above

htmlToPdf.convertHTMLString(html, '.\\pdf\\thepdf.pdf',
        function (error, success) {
            if (error) {
                console.log('Oh noes! Errorz!');
                console.log(error);
            } else {
                console.log('Woot! Success!');
                console.log(success);
            }
        }
    );

the console:

Woot! Success!
{ process_code: 1 }

this is success,but I can not find "thepdf.pdf" in .\pdf or anywhere.


Solution

  • use npm module html-pdf

     var fs = require('fs');
    var pdf = require('html-pdf');
    var html = fs.readFileSync('./home.html', 'utf8'); //to your html file
    var options = { format: 'Letter' };
     //in your case just your html code in place of html
         //pdf.create(<html><div>test</div></html>,.....)
    pdf.create(html, options).toFile('./gerrateddoc.pdf', function(err, res) {
      if (err) return console.log(err);
      console.log(res); // { filename: '/genrateddoc.pdf' } 
    });