Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我尝试将二进制图像插入 html 以使用节点模块 html-pdf 从 html doc 生成 PDF。
根据其他问题,我尝试了以下代码:
const pictureHtml = `<img src="data:image/png;base64","${binaryPicture}">`;
图片以二进制数据类型存储在 mongoDB 中。
如果无法使用模块 html-pdf,您能建议一个不同的模块吗?
img src必须是 base64string。我们需要将binaryPicture转换为base64string。我们有这样的代码
var base64data = Buffer.from(binaryPicture, 'binary').toString('base64'); const pictureHtml = `<img src="data:image/png;base64","${base64data}">`;