1
votes
app.get('/individual_report/:athlete_id', function(req, res) {
  database.select('*').from('participants').then(data => {
    if (data.length) {
      res.render('individual_report', {
        name: data
      });
      const hbsfile = fs.readFileSync(__dirname + '/../public/views/individual_report.hbs', 'utf8');
      const document = {
        template: hbsfile,
        context: {
          options: {
            dataForPDF: data,
            ssl_logo: '../public/static/assets/image/white_ssl_logo.png',
          },

    },
    path: __dirname + '/../public/reports/' + data[0].first_name + " " + data[0].last_name + '\'s scores.pdf'
  };
  pdf.create(document, options).then(res => {
    console.log(res)
  }).catch(error => {
    console.error(error)
  });
} else {
  res.json({
    msg: 'Invalid athlete ID'
  });
}
  }).catch(err => res.sendStatus(400));
});

The above node express route renders a html page and also generates a PDF using the HandleBars .hbs template.

<img class="ssl_logo" src="{{{options.ssl_logo}}}" alt="logo.png" width="120" height="50" />

This is what I have in the .hbs file that should display the logo image file.

The image is not rendered in the browser and also in the PDF file. However, the alt attribute is rendered on the browser and in the PDF. I looked into the console log and I get this unknown at the source attribute:

img class="ssl_logo" src(unknown) alt="logo.png" width="120" height="50"

I am using the dynamic-html-pdf node package to generate this report and can anyone suggest me something that might make this works? Thank you.

2

2 Answers

0
votes

Welp, I am going to answer my own post. For some reason this piece of code is not reading the local image file, so what I did was uploading the image to google drive, get the shareable link, google how to modify the shareable link because the link that is generated will not work in our code, and replace the image file address with the link.

Hope this will help those who is or will have this issue. (Ultimately you have to solve the problem yourself, haizzzz)

0
votes

just try to use file protocol

 ssl_logo: 'file://' + __dirname + '/public/static/assets/image/white_ssl_logo.png',

it will work normally even the SVG images will be generated