node-html-pdf businesscard example on Ubuntu

549 Views Asked by At

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?

2

There are 2 best solutions below

3
On

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

0
On

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