7

I am trying to use node-html-pdf (https://github.com/marcbachmann/node-html-pdf) node module on Ubuntu 16.04 and have started with the given businesscard example.

Unfortunately I was not able to generate this PDF.

First of all, I installed the module locally.

Then I copied the businesscard.html and image.png to my project and tried to execute the following code with no changes in it:

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' }
});

The result is a PDF with 2 black pages (ok), with the correct texts, but the format is much larger, the font is not right and I could not get the image in it.

Looks like some basic configuration, missing path or similar...

Any clues?

Aleks
  • 4,962
  • 1
  • 22
  • 39

2 Answers2

1

My guess is that if you open that .html file with your browser you will have the same (or similar) output.

Probably the link to the image src is broken and the font isn't imported.

Maybe you could try making your own basic html and then parse it to pdf, you should expect the .pdf to be similar to the .html

Aramil Rey
  • 3,026
  • 1
  • 17
  • 28
  • It's not a problem, browser displays it just fine. I suspect it's something with the basic setup, installation, parameters.. Surprising is that it is the module's own basic demo, I doubt it does not work (as it has 1500 stars on Github). – Aleks Jul 26 '17 at 08:39
  • I do not use this module, but reading their github it says it works with phantom.js so the `.pdf` probably is a screenshot of the rendered `.html`, and the configuration you posted seems ok, can u please add the code of `'./test/businesscard.html'` to your question? – Aramil Rey Jul 26 '17 at 15:06
  • Here is the HTML code for this example: https://github.com/marcbachmann/node-html-pdf/blob/master/example/businesscard.html I also tried to replace {{image}} with direct image name, but it did not help. As I told, letters and sizes are not good. – Aleks Jul 27 '17 at 14:26
1

One solution: try insatalling the fonts listed in the pdf...