Reputation: 3285
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?
Upvotes: 0
Views: 1336
Reputation: 3431
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}">`;
Upvotes: 1