Ad

Insert Binary Img As Html To Pdf With Node Html-pdf

- 1 answer

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?

Ad

Answer

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}">`;
Ad
source: stackoverflow.com
Ad