node.jspdfbinaryhtml-pdf

insert binary img as html to pdf with node html-pdf


I try to insert a binary image to html to generate a PDF from html doc with the node module html-pdf.

According to other questions I tried the following code:

const pictureHtml = `<img src="data:image/png;base64","${binaryPicture}">`;

The picture is stored in mongoDB as datatype Binary.

If not possible with the module html-pdf, can you suggest a different module?


Solution

  • img src must be base64string. We need convert binaryPicture to base64string .We have a code like this

    var base64data = Buffer.from(binaryPicture, 'binary').toString('base64');
    const pictureHtml = `<img src="data:image/png;base64","${base64data}">`;